File tree 3 files changed +13
-7
lines changed
3 files changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ public static Task Main()
18
18
#endregion
19
19
builder . RootComponents . Add < App > ( "app" ) ;
20
20
#endregion
21
+
21
22
serviceCollection . AddTransient (
22
23
provider => new HttpClient
23
24
{
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ public static partial class ClipboardService
35
35
static ClipboardService ( )
36
36
{
37
37
#if NETSTANDARD2_1
38
- if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Create ( "WEBASSEMBLY" ) ) )
38
+ if ( RuntimeInformation . OSDescription == "web" )
39
39
{
40
40
throw new Exception ( $ "The static class ClipboardService is not supported on Blazor. Instead inject an { nameof ( IClipboard ) } using { nameof ( ServiceExtensions ) } { nameof ( ServiceExtensions . InjectClipboard ) } .") ;
41
41
}
Original file line number Diff line number Diff line change 1
1
#if ! UAP
2
+ using System ;
3
+ using System . Runtime . InteropServices ;
2
4
using Microsoft . Extensions . DependencyInjection ;
3
5
4
6
namespace TextCopy
@@ -29,17 +31,20 @@ public static void InjectClipboard(this IServiceCollection services)
29
31
{
30
32
31
33
#if NETSTANDARD2_1
32
-
33
- var jsRuntimeType = System . Type . GetType ( "Microsoft.JSInterop.IJSRuntime, Microsoft.JSInterop" , false ) ;
34
- if ( jsRuntimeType != null )
34
+ if ( RuntimeInformation . OSDescription == "web" )
35
35
{
36
+ var jsRuntimeType = System . Type . GetType ( "Microsoft.JSInterop.IJSRuntime, Microsoft.JSInterop" , false ) ;
37
+ if ( jsRuntimeType == null )
38
+ {
39
+ throw new Exception ( "Running in Blazor but could not resolve JSInterop type." ) ;
40
+ }
36
41
var jsRuntime = provider . GetService ( jsRuntimeType ) ;
37
- if ( jsRuntime ! = null )
42
+ if ( jsRuntime = = null )
38
43
{
39
- return new BlazorClipboard ( jsRuntime ) ;
44
+ throw new Exception ( "Running in Blazor but could not get the JSInterop instance from the IServiceProvider." ) ;
40
45
}
46
+ return new BlazorClipboard ( jsRuntime ) ;
41
47
}
42
-
43
48
#endif
44
49
45
50
return new Clipboard ( ) ;
You can’t perform that action at this time.
0 commit comments