1- using System . Net . NetworkInformation ;
1+ using System ;
2+ using System . Net . NetworkInformation ;
23using System . Runtime . InteropServices ;
34using IO . Ably . Push ;
45using IO . Ably . Realtime ;
@@ -9,63 +10,51 @@ namespace IO.Ably
910 internal class Platform : IPlatform
1011 {
1112 private static readonly object Lock = new object ( ) ;
12- private Agent . PlatformRuntime ? _platformId ;
13+ private readonly Lazy < Agent . PlatformRuntime > _platformId ;
1314
14- static Platform ( )
15+ public Platform ( )
1516 {
16- Initialize ( ) ;
17+ _platformId = new Lazy < Agent . PlatformRuntime > ( DetectPlatformRuntime ) ;
1718 }
1819
19- internal static bool HookedUpToNetworkEvents { get ; private set ; }
20+ internal static bool HookedUpToNetworkEvents { get ; set ; }
2021
2122 // Use runtime detection via RuntimeInformation.FrameworkDescription
2223 // This detects the actual runtime version, not the compile-time target framework
2324 // This is important because netstandard2.0 assemblies can run on .NET 6/7/8/9+
2425 // and we want to report the actual runtime being used
25- public Agent . PlatformRuntime PlatformId
26+ public Agent . PlatformRuntime PlatformId => _platformId . Value ;
27+
28+ private Agent . PlatformRuntime DetectPlatformRuntime ( )
2629 {
27- get
28- {
29- if ( _platformId . HasValue )
30- {
31- return _platformId . Value ;
32- }
30+ // Default fallback for netstandard2.0 or unknown runtimes
31+ var platformId = Agent . PlatformRuntime . Netstandard20 ;
3332
34- // Default fallback for netstandard2.0 or unknown runtimes
35- _platformId = Agent . PlatformRuntime . Netstandard20 ;
33+ try
34+ {
35+ var frameworkDescription = RuntimeInformation . FrameworkDescription ;
3636
37- try
37+ if ( frameworkDescription . StartsWith ( ".NET 6." , StringComparison . OrdinalIgnoreCase ) )
3838 {
39- var frameworkDescription = RuntimeInformation . FrameworkDescription ;
40-
41- if ( frameworkDescription . StartsWith ( ".NET 6." , System . StringComparison . OrdinalIgnoreCase ) )
42- {
43- _platformId = Agent . PlatformRuntime . Net6 ;
44- }
45-
46- if ( frameworkDescription . StartsWith ( ".NET 7." , System . StringComparison . OrdinalIgnoreCase ) )
47- {
48- _platformId = Agent . PlatformRuntime . Net7 ;
49- }
39+ platformId = Agent . PlatformRuntime . Net6 ;
5040 }
51- catch
41+ else if ( frameworkDescription . StartsWith ( ".NET 7." , StringComparison . OrdinalIgnoreCase ) )
5242 {
53- // fall back to Netstandard20
43+ platformId = Agent . PlatformRuntime . Net7 ;
5444 }
55-
56- return _platformId . Value ;
5745 }
46+ catch
47+ {
48+ // fall back to Netstandard20
49+ }
50+
51+ return platformId ;
5852 }
5953
6054 public ITransportFactory TransportFactory => null ;
6155
6256 public IMobileDevice MobileDevice { get ; set ; }
6357
64- internal static void Initialize ( )
65- {
66- HookedUpToNetworkEvents = false ;
67- }
68-
6958 public void RegisterOsNetworkStateChanged ( )
7059 {
7160 lock ( Lock )
0 commit comments