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.


 


Wednesday, May 24, 2006 11:10:24 PM (Eastern Daylight Time, UTC-04:00) #    Comments [3]  | 

 

Thursday, May 25, 2006 5:42:38 PM (Eastern Daylight Time, UTC-04:00)
I am sure I am missing the point but... why not check the System.Environment.OSVersion.Platform ?
Friday, May 26, 2006 11:37:24 AM (Eastern Daylight Time, UTC-04:00)
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 :)
Sunday, May 28, 2006 10:20:06 AM (Eastern Daylight Time, UTC-04:00)
OK, seems I was missing the "fun" point :-)
Comments are closed.
All content © 2008, Mark Arteaga
On this page
Related Sites
Archives
Sitemap
Disclaimer

Powered by: newtelligence dasBlog 1.9.7174.0

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

Send mail to the author(s) E-mail

Theme design by Jelle Druyts