Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
OSPlatform.cs
Go to the documentation of this file.
2
4
5public readonly struct OSPlatform : IEquatable<OSPlatform>
6{
7 public static OSPlatform FreeBSD { get; } = new OSPlatform("FREEBSD");
8
9
10 public static OSPlatform Linux { get; } = new OSPlatform("LINUX");
11
12
13 public static OSPlatform OSX { get; } = new OSPlatform("OSX");
14
15
16 public static OSPlatform Windows { get; } = new OSPlatform("WINDOWS");
17
18
19 internal string Name { get; }
20
21 private OSPlatform(string osPlatform)
22 {
23 if (osPlatform == null)
24 {
25 throw new ArgumentNullException("osPlatform");
26 }
27 if (osPlatform.Length == 0)
28 {
29 throw new ArgumentException(System.SR.Argument_EmptyValue, "osPlatform");
30 }
31 Name = osPlatform;
32 }
33
34 public static OSPlatform Create(string osPlatform)
35 {
36 return new OSPlatform(osPlatform);
37 }
38
39 public bool Equals(OSPlatform other)
40 {
41 return Equals(other.Name);
42 }
43
44 internal bool Equals(string other)
45 {
46 return string.Equals(Name, other, StringComparison.OrdinalIgnoreCase);
47 }
48
49 public override bool Equals([NotNullWhen(true)] object? obj)
50 {
51 if (obj is OSPlatform other)
52 {
53 return Equals(other);
54 }
55 return false;
56 }
57
58 public override int GetHashCode()
59 {
60 if (Name != null)
61 {
62 return StringComparer.OrdinalIgnoreCase.GetHashCode(Name);
63 }
64 return 0;
65 }
66
67 public override string ToString()
68 {
69 return Name ?? string.Empty;
70 }
71
72 public static bool operator ==(OSPlatform left, OSPlatform right)
73 {
74 return left.Equals(right);
75 }
76
77 public static bool operator !=(OSPlatform left, OSPlatform right)
78 {
79 return !(left == right);
80 }
81}
static string Argument_EmptyValue
Definition SR.cs:14
Definition SR.cs:7
static StringComparer OrdinalIgnoreCase
override bool Equals([NotNullWhen(true)] object? obj)
Definition OSPlatform.cs:49
static bool operator==(OSPlatform left, OSPlatform right)
Definition OSPlatform.cs:72
static OSPlatform Create(string osPlatform)
Definition OSPlatform.cs:34
static bool operator!=(OSPlatform left, OSPlatform right)
Definition OSPlatform.cs:77