Archives For .NET Framework

I’ve been getting a few emails/questions on ‘Leveraging Existing .NET Code’ section of my Platform In Your Pocket session for TechDays so just wanted to share what I’ve been sharing with those emails.

First all credits go to Daniel Moth for his Sharing Assets between Windows Mobile and Windows Desktop he did back in 2006.  Daniel now works for the Parallel Computing Platform so be sure to check out his blog for tips and check out his PDC session here.

I only spent about 15mins on leveraging existing code and is only a small fraction of what Daniel covered in his session.  I always reference his blog posts when responding to emails so I’ll do the same here. His most recent post is on Sharing Assets Between the .NET Compact Framework and the .NET Framework has all relevant links.  There is an article in MSDN Magazine article which also goes through the concepts.

If you are a .NET developer looking at writing a Windows Mobile application make sure you leverage your existing code so you can get your product to your customers faster.

Good Luck and if you have more questions feel free to contact me!

Well the title is a little vague but when writing an applicaiton how do you know what platform your code is running on?  Not if you are running on Windows Mobile PocketPC or SmartPhone (you can use OpenNETCF.WindowsCE.DeviceManagement.PlatformName), but if you are running on the desktop using the .NET Framework or a device using the .NET Compact Framework.  For the Mobility Workshop on Saturday I wanted to show a way to distingush if the code was on the .NET Framework or on the Compact Framework so I came up with this class (which was derived from a typed dataset generated code using Compact Framework)


 


namespace OpenNETCF
{
   public class Utility
   {
      public static bool IsDesktop
      {
         get
         {
            // Determine if this instance is running against .NET Framework by using the MSCoreLib PublicKeyToken
            System.Reflection.Assembly mscorlibAssembly = typeof(int).Assembly;
            if ((mscorlibAssembly != null))
               return mscorlibAssembly.FullName.ToUpper().EndsWith(“B77A5C561934E089”);
            return false;
         }
      }

      public static bool IsDevice
      {
         get
         {
            // Determine if this instance is running against .NET Compact Framework by using the MSCoreLib PublicKeyToken
            System.Reflection.Assembly mscorlibAssembly = typeof(int).Assembly;
            if ((mscorlibAssembly != null))
               return mscorlibAssembly.FullName.ToUpper().EndsWith(“969DB8053D3322AC”);
            return false;
         }
      }
   }
}


Basically you check the public key of the assembly.  If you get “B77A5C561934E089” then you are on the Full Fx and if you get “969DB8053D3322AC” you are running on the Compact Framework.