forked from IronLanguages/ironpython3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFakeInteropServices.cs
More file actions
59 lines (44 loc) · 2.14 KB
/
FakeInteropServices.cs
File metadata and controls
59 lines (44 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 license.
// See the LICENSE file in the project root for more information.
using System;
using System.IO;
namespace IronPython {
#if !FEATURE_RUNTIMEINFORMATION
internal static class RuntimeInformation {
private static readonly OSPlatform _osPlatform;
static RuntimeInformation() {
switch (Environment.OSVersion.Platform) {
case PlatformID.Unix:
if (Directory.Exists("/Applications") & Directory.Exists("/System") & Directory.Exists("/Users") & Directory.Exists("/Volumes"))
_osPlatform = OSPlatform.OSX;
else
_osPlatform = OSPlatform.Linux;
break;
case PlatformID.MacOSX:
_osPlatform = OSPlatform.OSX;
break;
default:
_osPlatform = OSPlatform.Windows;
break;
}
}
public static bool IsOSPlatform(OSPlatform osPlatform) => _osPlatform == osPlatform;
}
internal readonly struct OSPlatform : IEquatable<OSPlatform> {
private readonly string _osPlatform;
public static OSPlatform Linux { get; } = new OSPlatform("LINUX");
public static OSPlatform OSX { get; } = new OSPlatform("OSX");
public static OSPlatform Windows { get; } = new OSPlatform("WINDOWS");
private OSPlatform(string osPlatform) {
_osPlatform = osPlatform;
}
public bool Equals(OSPlatform other) => _osPlatform.Equals(other._osPlatform);
public override bool Equals(object obj) => obj is OSPlatform other && Equals(other);
public override int GetHashCode() => _osPlatform == null ? 0 : _osPlatform.GetHashCode();
public override string ToString() => _osPlatform ?? string.Empty;
public static bool operator ==(OSPlatform left, OSPlatform right) => left.Equals(right);
public static bool operator !=(OSPlatform left, OSPlatform right) => !(left == right);
}
#endif
}