11using System ;
2- using System . IO ;
32using System . Runtime . InteropServices ;
43
54namespace LibGit2Sharp . Core
@@ -13,68 +12,29 @@ internal enum OperatingSystemType
1312
1413 internal static class Platform
1514 {
16- private static Lazy < OperatingSystemType > _operatingSystem = new Lazy < OperatingSystemType > (
17- DetermineOperatingSystem ,
18- System . Threading . LazyThreadSafetyMode . PublicationOnly ) ;
15+ public static string ProcessorArchitecture => IntPtr . Size == 8 ? "x64" : "x86" ;
1916
20- public static string ProcessorArchitecture
17+ public static OperatingSystemType OperatingSystem
2118 {
22- get { return IntPtr . Size == 8 ? "x64" : "x86" ; }
23- }
24-
25- public static OperatingSystemType OperatingSystem => _operatingSystem . Value ;
26-
27- private static OperatingSystemType DetermineOperatingSystem ( )
28- {
29- #if DESKTOP
30- // See http://www.mono-project.com/docs/faq/technical/#how-to-detect-the-execution-platform
31- switch ( ( int ) Environment . OSVersion . Platform )
19+ get
3220 {
33- case 4 :
34- case 128 :
21+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
22+ {
23+ return OperatingSystemType . Windows ;
24+ }
25+
26+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) )
27+ {
3528 return OperatingSystemType . Unix ;
29+ }
3630
37- case 6 :
31+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) )
32+ {
3833 return OperatingSystemType . MacOSX ;
34+ }
3935
40- default :
41- return OperatingSystemType . Windows ;
42- }
43- #else
44- try
45- {
46- return OperatingSystem_CoreFxStyle ( ) ;
47- }
48- catch ( FileNotFoundException )
49- {
50- // We're probably running on .NET 4.6.1 or earlier where the API isn't available.
51- // This would suggest we're running on Windows. Although if our portable library
52- // is being used on mono, it could be *nix or OSX too.
53- return OperatingSystemType . Windows ;
54- }
55- #endif
56- }
57-
58- #if ! DESKTOP
59- private static OperatingSystemType OperatingSystem_CoreFxStyle ( )
60- {
61- if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
62- {
63- return OperatingSystemType . Windows ;
64- }
65- else if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) )
66- {
67- return OperatingSystemType . Unix ;
68- }
69- else if ( RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) )
70- {
71- return OperatingSystemType . MacOSX ;
72- }
73- else
74- {
7536 throw new InvalidOperationException ( ) ;
7637 }
7738 }
78- #endif
7939 }
8040}
0 commit comments