Desktop or Device…How to decide?

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.




 


Warning: count(): Parameter must be an array or an object that implements Countable in /nfs/c07/h02/mnt/110221/domains/markarteaga.com/html/wp-includes/class-wp-comment-query.php on line 405

3 thoughts on “Desktop or Device…How to decide?”

  1. The main point was to see if you are running using the Compact Framework or the full Framework. You can use System.Environment.OSVersion.Platform but what fun is that 🙂

Leave a Reply