4
4
using System ;
5
5
using System . Globalization ;
6
6
using System . IO ;
7
+ using System . Runtime . CompilerServices ;
8
+ using System . Runtime . InteropServices ;
9
+ using System . Threading . Tasks ;
7
10
8
11
namespace ServiceStack . Text
9
12
{
@@ -18,12 +21,12 @@ static Env()
18
21
IsNetStandard = true ;
19
22
try
20
23
{
21
- IsLinux = System . Runtime . InteropServices . RuntimeInformation . IsOSPlatform ( System . Runtime . InteropServices . OSPlatform . Linux ) ;
22
- IsWindows = System . Runtime . InteropServices . RuntimeInformation . IsOSPlatform ( System . Runtime . InteropServices . OSPlatform . Windows ) ;
23
- IsOSX = System . Runtime . InteropServices . RuntimeInformation . IsOSPlatform ( System . Runtime . InteropServices . OSPlatform . OSX ) ;
24
- IsNetCore3 = System . Runtime . InteropServices . RuntimeInformation . FrameworkDescription . StartsWith ( ".NET Core 3" ) ;
24
+ IsLinux = RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) ;
25
+ IsWindows = RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ;
26
+ IsOSX = RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) ;
27
+ IsNetCore3 = RuntimeInformation . FrameworkDescription . StartsWith ( ".NET Core 3" ) ;
25
28
26
- var fxDesc = System . Runtime . InteropServices . RuntimeInformation . FrameworkDescription ;
29
+ var fxDesc = RuntimeInformation . FrameworkDescription ;
27
30
IsMono = fxDesc . Contains ( "Mono" ) ;
28
31
IsNetCore = fxDesc . StartsWith ( ".NET Core" , StringComparison . OrdinalIgnoreCase ) ;
29
32
}
@@ -79,7 +82,7 @@ static Env()
79
82
IsAndroid = AssemblyUtils . FindType ( "Android.Manifest" ) != null ;
80
83
if ( IsOSX && IsMono )
81
84
{
82
- var runtimeDir = System . Runtime . InteropServices . RuntimeEnvironment . GetRuntimeDirectory ( ) ;
85
+ var runtimeDir = RuntimeEnvironment . GetRuntimeDirectory ( ) ;
83
86
//iOS detection no longer trustworthy so assuming iOS based on some current heuristics. TODO: improve iOS detection
84
87
IsIOS = runtimeDir . StartsWith ( "/private/var" ) ||
85
88
runtimeDir . Contains ( "/CoreSimulator/Devices/" ) ;
@@ -99,11 +102,11 @@ static Env()
99
102
VersionString = ServiceStackVersion . ToString ( CultureInfo . InvariantCulture ) ;
100
103
101
104
ServerUserAgent = "ServiceStack/"
102
- + VersionString + " "
103
- + PclExport . Instance . PlatformName
104
- + ( IsMono ? "/Mono" : "" )
105
- + ( IsLinux ? "/Linux" : IsOSX ? "/OSX" : IsUnix ? "/Unix" : IsWindows ? "/Windows" : "/UnknownOS" )
106
- + ( IsIOS ? "/iOS" : IsAndroid ? "/Android" : IsUWP ? "/UWP" : "" ) ;
105
+ + VersionString + " "
106
+ + PclExport . Instance . PlatformName
107
+ + ( IsMono ? "/Mono" : "" )
108
+ + ( IsLinux ? "/Linux" : IsOSX ? "/OSX" : IsUnix ? "/Unix" : IsWindows ? "/Windows" : "/UnknownOS" )
109
+ + ( IsIOS ? "/iOS" : IsAndroid ? "/Android" : IsUWP ? "/UWP" : "" ) ;
107
110
108
111
__releaseDate = new DateTime ( 2001 , 01 , 01 ) ;
109
112
}
@@ -216,7 +219,7 @@ private static bool IsRunningAsUwp()
216
219
{
217
220
try
218
221
{
219
- IsNetNative = System . Runtime . InteropServices . RuntimeInformation . FrameworkDescription . StartsWith ( ".NET Native" , StringComparison . OrdinalIgnoreCase ) ;
222
+ IsNetNative = RuntimeInformation . FrameworkDescription . StartsWith ( ".NET Native" , StringComparison . OrdinalIgnoreCase ) ;
220
223
return IsInAppContainer || IsNetNative ;
221
224
}
222
225
catch ( Exception ) { }
@@ -294,9 +297,18 @@ private static bool IsInAppContainer
294
297
}
295
298
}
296
299
297
- [ System . Runtime . InteropServices . DllImport ( "kernel32.dll" , ExactSpelling = true ) ]
300
+ [ DllImport ( "kernel32.dll" , ExactSpelling = true ) ]
298
301
private static extern int GetCurrentApplicationUserModelId ( ref uint applicationUserModelIdLength , byte [ ] applicationUserModelId ) ;
299
302
#endif
300
-
303
+
304
+ public static bool ContinueOnCapturedContext = false ;
305
+
306
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
307
+ public static ConfiguredTaskAwaitable ConfigAwait ( this Task task ) =>
308
+ task . ConfigureAwait ( ContinueOnCapturedContext ) ;
309
+
310
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
311
+ public static ConfiguredTaskAwaitable < object > ConfigAwait ( this Task < object > task ) =>
312
+ task . ConfigureAwait ( ContinueOnCapturedContext ) ;
301
313
}
302
314
}
0 commit comments