Beispiel #1
0
        static PlatformType GetPlatformType()
        {
            if (AppDom.FindAssembly("Mono.Android", false) != null)
            {
                return(PlatformType.Android);
            }
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                return(PlatformType.Windows);
            }
            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                return(PlatformType.MacOS);
            }
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                return(PlatformType.Linux);
            }
            try
            {
                if (File.Exists("/usr/lib/libc.dylib"))
                {
                    return(PlatformType.MacOS);
                }
            }
            catch
            {
                /*Exception on Android on this one... why ?*/
            }

            string osType = RuntimeInformation.OSDescription.ToLower();

            if (osType.StartsWith("linux"))
            {
                return(PlatformType.Linux);
            }
            if (osType.StartsWith("darwin"))
            {
                return(PlatformType.MacOS);
            }
            if (osType.StartsWith("solaris"))
            {
                return(PlatformType.Solaris);
            }
            if (osType.StartsWith("bsd"))
            {
                return(PlatformType.BSD);
            }
            if (osType.StartsWith("msys"))
            {
                return(PlatformType.Windows);
            }
            if (osType.StartsWith("cygwin"))
            {
                return(PlatformType.Windows);
            }
            return(PlatformType.UnknownUnix);
        }
Beispiel #2
0
        static PlatformType GetPlatformType()
        {
            switch ((int)Environment.OSVersion.Platform)
            {
            case 0:     /*Win32S*/
            case 1:     /*Win32NT*/
            case 2:     /*Win32Windows*/
                return(PlatformType.Windows);

            case 3:     /*Windows CE / Compact Framework*/
                return(PlatformType.CompactFramework);

            case 4:     /*Unix, mono returns this on all platforms except windows*/
                if (AppDom.FindAssembly("Mono.Android", false) != null)
                {
                    return(PlatformType.Android);
                }

                try
                {
                    if (File.Exists("/usr/lib/libc.dylib"))
                    {
                        return(PlatformType.MacOS);
                    }
                }
                catch
                {     /*Exception on Android on this one... why ?*/
                }

                string osType = SystemVersionString.ToLower();
                if (osType.StartsWith("linux"))
                {
                    return(PlatformType.Linux);
                }
                if (osType.StartsWith("darwin"))
                {
                    return(PlatformType.MacOS);
                }
                if (osType.StartsWith("solaris"))
                {
                    return(PlatformType.Solaris);
                }
                if (osType.StartsWith("bsd"))
                {
                    return(PlatformType.BSD);
                }
                if (osType.StartsWith("msys"))
                {
                    return(PlatformType.Windows);
                }
                if (osType.StartsWith("cygwin"))
                {
                    return(PlatformType.Windows);
                }
                return(PlatformType.UnknownUnix);

            case 5:     /*Xbox*/
                return(PlatformType.Xbox);

            case 6:     /*MacOSX*/
                return(PlatformType.MacOS);

            case 128:
                return(PlatformType.UnknownUnix);

            default:
                return(PlatformType.Unknown);
            }
        }
Beispiel #3
0
 static bool GetIsAndroid()
 {
     return(AppDom.FindType("Android.Runtime", null, AppDom.LoadMode.NoException) != null);
 }
Beispiel #4
0
 static bool GetIsMono()
 {
     return(AppDom.FindType("Mono.Runtime", null, AppDom.LoadMode.NoException) != null);
 }