Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
FrameworkName.cs
Go to the documentation of this file.
2
4
5public sealed class FrameworkName : IEquatable<FrameworkName?>
6{
7 private readonly string _identifier;
8
9 private readonly Version _version;
10
11 private readonly string _profile;
12
13 private string _fullName;
14
15 public string Identifier => _identifier;
16
18
19 public string Profile => _profile;
20
21 public string FullName
22 {
23 get
24 {
25 if (_fullName == null)
26 {
27 _fullName = (string.IsNullOrEmpty(Profile) ? $"{Identifier}{",Version=v"}{Version}" : $"{Identifier}{",Version=v"}{Version}{",Profile="}{Profile}");
28 }
29 return _fullName;
30 }
31 }
32
33 public override bool Equals([NotNullWhen(true)] object? obj)
34 {
35 return Equals(obj as FrameworkName);
36 }
37
38 public bool Equals([NotNullWhen(true)] FrameworkName? other)
39 {
40 if ((object)other == null)
41 {
42 return false;
43 }
44 if (Identifier == other.Identifier && Version == other.Version)
45 {
46 return Profile == other.Profile;
47 }
48 return false;
49 }
50
51 public override int GetHashCode()
52 {
53 return Identifier.GetHashCode() ^ Version.GetHashCode() ^ Profile.GetHashCode();
54 }
55
56 public override string ToString()
57 {
58 return FullName;
59 }
60
61 public FrameworkName(string identifier, Version version)
62 : this(identifier, version, null)
63 {
64 }
65
66 public FrameworkName(string identifier, Version version, string? profile)
67 {
68 if (identifier == null)
69 {
70 throw new ArgumentNullException("identifier");
71 }
72 identifier = identifier.Trim();
73 if (identifier.Length == 0)
74 {
75 throw new ArgumentException(SR.Format(SR.net_emptystringcall, "identifier"), "identifier");
76 }
77 if (version == null)
78 {
79 throw new ArgumentNullException("version");
80 }
81 _identifier = identifier;
82 _version = version;
83 _profile = ((profile == null) ? string.Empty : profile.Trim());
84 }
85
86 public FrameworkName(string frameworkName)
87 {
88 if (frameworkName == null)
89 {
90 throw new ArgumentNullException("frameworkName");
91 }
92 if (frameworkName.Length == 0)
93 {
94 throw new ArgumentException(SR.Format(SR.net_emptystringcall, "frameworkName"), "frameworkName");
95 }
96 string[] array = frameworkName.Split(',');
97 if (array.Length < 2 || array.Length > 3)
98 {
99 throw new ArgumentException(SR.Argument_FrameworkNameTooShort, "frameworkName");
100 }
101 _identifier = array[0].Trim();
102 if (_identifier.Length == 0)
103 {
104 throw new ArgumentException(SR.Argument_FrameworkNameInvalid, "frameworkName");
105 }
106 bool flag = false;
107 _profile = string.Empty;
108 for (int i = 1; i < array.Length; i++)
109 {
110 string text = array[i];
111 int num = text.IndexOf('=');
112 if (num == -1 || num != text.LastIndexOf('='))
113 {
114 throw new ArgumentException(SR.Argument_FrameworkNameInvalid, "frameworkName");
115 }
116 ReadOnlySpan<char> span = text.AsSpan(0, num).Trim();
117 ReadOnlySpan<char> input = text.AsSpan(num + 1).Trim();
118 if (MemoryExtensions.Equals(span, "Version", StringComparison.OrdinalIgnoreCase))
119 {
120 flag = true;
121 if (input.Length > 0 && (input[0] == 'v' || input[0] == 'V'))
122 {
123 input = input.Slice(1);
124 }
125 try
126 {
128 }
129 catch (Exception innerException)
130 {
131 throw new ArgumentException(SR.Argument_FrameworkNameInvalidVersion, "frameworkName", innerException);
132 }
133 }
134 else
135 {
136 if (!MemoryExtensions.Equals(span, "Profile", StringComparison.OrdinalIgnoreCase))
137 {
138 throw new ArgumentException(SR.Argument_FrameworkNameInvalid, "frameworkName");
139 }
140 if (input.Length > 0)
141 {
142 _profile = input.ToString();
143 }
144 }
145 }
146 if (!flag)
147 {
149 }
150 }
151
152 public static bool operator ==(FrameworkName? left, FrameworkName? right)
153 {
154 return left?.Equals(right) ?? ((object)right == null);
155 }
156
157 public static bool operator !=(FrameworkName? left, FrameworkName? right)
158 {
159 return !(left == right);
160 }
161}
static bool Equals(this ReadOnlySpan< char > span, ReadOnlySpan< char > other, StringComparison comparisonType)
FrameworkName(string identifier, Version version)
bool Equals([NotNullWhen(true)] FrameworkName? other)
static bool operator==(FrameworkName? left, FrameworkName? right)
override bool Equals([NotNullWhen(true)] object? obj)
FrameworkName(string identifier, Version version, string? profile)
static bool operator!=(FrameworkName? left, FrameworkName? right)
static string Argument_FrameworkNameInvalidVersion
Definition SR.cs:2154
static string Argument_FrameworkNameInvalid
Definition SR.cs:2152
static string Argument_FrameworkNameTooShort
Definition SR.cs:2158
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string Argument_FrameworkNameMissingVersion
Definition SR.cs:2156
static string net_emptystringcall
Definition SR.cs:14
Definition SR.cs:7
Version(int major, int minor, int build, int revision)
Definition Version.cs:47
static Version Parse(string input)
Definition Version.cs:310
override int GetHashCode()
Definition Version.cs:211