@@ -24,6 +24,19 @@ static Env()
24
24
25
25
IsAndroid = AssemblyUtils . FindType ( "Android.Manifest" ) != null ;
26
26
27
+ try
28
+ {
29
+ IsOSX = AssemblyUtils . FindType ( "Mono.AppKit" ) != null ;
30
+ #if NET45
31
+ IsWindows = ! string . IsNullOrEmpty ( Environment . GetEnvironmentVariable ( "windir" ) ) ;
32
+ if ( File . Exists ( @"/System/Library/CoreServices/SystemVersion.plist" ) )
33
+ IsOSX = true ;
34
+ string osType = File . Exists ( @"/proc/sys/kernel/ostype" ) ? File . ReadAllText ( @"/proc/sys/kernel/ostype" ) : null ;
35
+ IsLinux = osType ? . IndexOf ( "Linux" , StringComparison . OrdinalIgnoreCase ) >= 0 ;
36
+ #endif
37
+ }
38
+ catch ( Exception ignore ) { }
39
+
27
40
//Throws unhandled exception if not called from the main thread
28
41
//IsWinRT = AssemblyUtils.FindType("Windows.ApplicationModel") != null;
29
42
@@ -36,13 +49,20 @@ static Env()
36
49
IsWindowsStore = true ;
37
50
}
38
51
39
- #if PCL || NETSTANDARD1_1
40
- IsUnix = IsMono ;
41
- IsWin = ! IsUnix ;
52
+ #if PCL
53
+ IsUnix = IsMono || IsOSX || IsLinux ;
54
+ IsWindows = ! IsUnix ;
55
+ #elif NETSTANDARD1_1
56
+ IsLinux = System . Runtime . InteropServices . RuntimeInformation . IsOSPlatform ( System . Runtime . InteropServices . OSPlatform . Linux ) ;
57
+ IsWindows = System . Runtime . InteropServices . RuntimeInformation . IsOSPlatform ( System . Runtime . InteropServices . OSPlatform . Windows ) ;
58
+ IsOSX = System . Runtime . InteropServices . RuntimeInformation . IsOSPlatform ( System . Runtime . InteropServices . OSPlatform . OSX ) ;
59
+ IsUnix = IsOSX || IsLinux ;
42
60
#else
43
61
var platform = ( int ) Environment . OSVersion . Platform ;
44
- IsUnix = ( platform == 4 ) || ( platform == 6 ) || ( platform == 128 ) ;
45
- IsWin = Environment . GetEnvironmentVariable ( "OS" ) ? . IndexOf ( "Windows" , StringComparison . OrdinalIgnoreCase ) >= 0 ;
62
+ IsUnix = platform == 4 || platform == 6 || platform == 128 ;
63
+ IsLinux = IsUnix ;
64
+ if ( Environment . GetEnvironmentVariable ( "OS" ) ? . IndexOf ( "Windows" , StringComparison . OrdinalIgnoreCase ) >= 0 )
65
+ IsWindows = true ;
46
66
#endif
47
67
48
68
ServerUserAgent = "ServiceStack/" +
@@ -59,9 +79,13 @@ static Env()
59
79
60
80
public static decimal ServiceStackVersion = 4.00m ;
61
81
82
+ public static bool IsLinux { get ; set ; }
83
+
84
+ public static bool IsOSX { get ; set ; }
85
+
62
86
public static bool IsUnix { get ; set ; }
63
87
64
- public static bool IsWin { get ; set ; }
88
+ public static bool IsWindows { get ; set ; }
65
89
66
90
public static bool IsMono { get ; set ; }
67
91
0 commit comments