mscorlib(4.0.0.0) API with additions
FrameworkName.cs
1 using System.Text;
2 
4 {
7  [global::__DynamicallyInvokable]
8  public sealed class FrameworkName : IEquatable<FrameworkName>
9  {
10  private readonly string m_identifier;
11 
12  private readonly Version m_version;
13 
14  private readonly string m_profile;
15 
16  private string m_fullName;
17 
18  private const char c_componentSeparator = ',';
19 
20  private const char c_keyValueSeparator = '=';
21 
22  private const char c_versionValuePrefix = 'v';
23 
24  private const string c_versionKey = "Version";
25 
26  private const string c_profileKey = "Profile";
27 
30  [global::__DynamicallyInvokable]
31  public string Identifier
32  {
33  [global::__DynamicallyInvokable]
34  get
35  {
36  return m_identifier;
37  }
38  }
39 
42  [global::__DynamicallyInvokable]
43  public Version Version
44  {
45  [global::__DynamicallyInvokable]
46  get
47  {
48  return m_version;
49  }
50  }
51 
54  [global::__DynamicallyInvokable]
55  public string Profile
56  {
57  [global::__DynamicallyInvokable]
58  get
59  {
60  return m_profile;
61  }
62  }
63 
66  [global::__DynamicallyInvokable]
67  public string FullName
68  {
69  [global::__DynamicallyInvokable]
70  get
71  {
72  if (m_fullName == null)
73  {
74  StringBuilder stringBuilder = new StringBuilder();
75  stringBuilder.Append(Identifier);
76  stringBuilder.Append(',');
77  stringBuilder.Append("Version").Append('=');
78  stringBuilder.Append('v');
79  stringBuilder.Append(Version);
80  if (!string.IsNullOrEmpty(Profile))
81  {
82  stringBuilder.Append(',');
83  stringBuilder.Append("Profile").Append('=');
84  stringBuilder.Append(Profile);
85  }
86  m_fullName = stringBuilder.ToString();
87  }
88  return m_fullName;
89  }
90  }
91 
96  [global::__DynamicallyInvokable]
97  public override bool Equals(object obj)
98  {
99  return Equals(obj as FrameworkName);
100  }
101 
106  [global::__DynamicallyInvokable]
107  public bool Equals(FrameworkName other)
108  {
109  if ((object)other == null)
110  {
111  return false;
112  }
113  if (Identifier == other.Identifier && Version == other.Version)
114  {
115  return Profile == other.Profile;
116  }
117  return false;
118  }
119 
122  [global::__DynamicallyInvokable]
123  public override int GetHashCode()
124  {
125  return Identifier.GetHashCode() ^ Version.GetHashCode() ^ Profile.GetHashCode();
126  }
127 
130  [global::__DynamicallyInvokable]
131  public override string ToString()
132  {
133  return FullName;
134  }
135 
144  [global::__DynamicallyInvokable]
145  public FrameworkName(string identifier, Version version)
146  : this(identifier, version, null)
147  {
148  }
149 
159  [global::__DynamicallyInvokable]
160  public FrameworkName(string identifier, Version version, string profile)
161  {
162  if (identifier == null)
163  {
164  throw new ArgumentNullException("identifier");
165  }
166  if (identifier.Trim().Length == 0)
167  {
168  throw new ArgumentException(SR.GetString("net_emptystringcall", "identifier"), "identifier");
169  }
170  if (version == null)
171  {
172  throw new ArgumentNullException("version");
173  }
174  m_identifier = identifier.Trim();
175  m_version = (Version)version.Clone();
176  m_profile = ((profile == null) ? string.Empty : profile.Trim());
177  }
178 
188  [global::__DynamicallyInvokable]
189  public FrameworkName(string frameworkName)
190  {
191  if (frameworkName == null)
192  {
193  throw new ArgumentNullException("frameworkName");
194  }
195  if (frameworkName.Length == 0)
196  {
197  throw new ArgumentException(SR.GetString("net_emptystringcall", "frameworkName"), "frameworkName");
198  }
199  string[] array = frameworkName.Split(',');
200  if (array.Length < 2 || array.Length > 3)
201  {
202  throw new ArgumentException(SR.GetString("Argument_FrameworkNameTooShort"), "frameworkName");
203  }
204  m_identifier = array[0].Trim();
205  if (m_identifier.Length == 0)
206  {
207  throw new ArgumentException(SR.GetString("Argument_FrameworkNameInvalid"), "frameworkName");
208  }
209  bool flag = false;
210  m_profile = string.Empty;
211  for (int i = 1; i < array.Length; i++)
212  {
213  string[] array2 = array[i].Split('=');
214  if (array2.Length != 2)
215  {
216  throw new ArgumentException(SR.GetString("Argument_FrameworkNameInvalid"), "frameworkName");
217  }
218  string text = array2[0].Trim();
219  string text2 = array2[1].Trim();
220  if (text.Equals("Version", StringComparison.OrdinalIgnoreCase))
221  {
222  flag = true;
223  if (text2.Length > 0 && (text2[0] == 'v' || text2[0] == 'V'))
224  {
225  text2 = text2.Substring(1);
226  }
227  try
228  {
229  m_version = new Version(text2);
230  }
231  catch (Exception innerException)
232  {
233  throw new ArgumentException(SR.GetString("Argument_FrameworkNameInvalidVersion"), "frameworkName", innerException);
234  }
235  continue;
236  }
237  if (text.Equals("Profile", StringComparison.OrdinalIgnoreCase))
238  {
239  if (!string.IsNullOrEmpty(text2))
240  {
241  m_profile = text2;
242  }
243  continue;
244  }
245  throw new ArgumentException(SR.GetString("Argument_FrameworkNameInvalid"), "frameworkName");
246  }
247  if (!flag)
248  {
249  throw new ArgumentException(SR.GetString("Argument_FrameworkNameMissingVersion"), "frameworkName");
250  }
251  }
252 
258  [global::__DynamicallyInvokable]
259  public static bool operator ==(FrameworkName left, FrameworkName right)
260  {
261  return left?.Equals(right) ?? ((object)right == null);
262  }
263 
269  [global::__DynamicallyInvokable]
270  public static bool operator !=(FrameworkName left, FrameworkName right)
271  {
272  return !(left == right);
273  }
274  }
275 }
override int GetHashCode()
Returns a hash code for the current T:System.Version object.
Definition: Version.cs:425
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
static bool operator !=(FrameworkName left, FrameworkName right)
Returns a value that indicates whether two T:System.Runtime.Versioning.FrameworkName objects represen...
unsafe override string ToString()
Converts the value of this instance to a T:System.String.
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
Definition: __Canon.cs:3
string Identifier
Gets the identifier of this T:System.Runtime.Versioning.FrameworkName object.
FrameworkName(string identifier, Version version, string profile)
Initializes a new instance of the T:System.Runtime.Versioning.FrameworkName class from a string,...
Version Version
Gets the version of this T:System.Runtime.Versioning.FrameworkName object.
string FullName
Gets the full name of this T:System.Runtime.Versioning.FrameworkName object.
bool Equals(FrameworkName other)
Returns a value that indicates whether this T:System.Runtime.Versioning.FrameworkName instance repres...
FrameworkName(string frameworkName)
Initializes a new instance of the T:System.Runtime.Versioning.FrameworkName class from a string that ...
StringBuilder Append(char value, int repeatCount)
Appends a specified number of copies of the string representation of a Unicode character to this inst...
FrameworkName(string identifier, Version version)
Initializes a new instance of the T:System.Runtime.Versioning.FrameworkName class from a string and a...
string Profile
Gets the profile name of this T:System.Runtime.Versioning.FrameworkName object.
override string ToString()
Returns the string representation of this T:System.Runtime.Versioning.FrameworkName object.
Represents the version number of an assembly, operating system, or the common language runtime....
Definition: Version.cs:11
static bool operator==(FrameworkName left, FrameworkName right)
Returns a value that indicates whether two T:System.Runtime.Versioning.FrameworkName objects represen...
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
The exception that is thrown when one of the arguments provided to a method is not valid.
Represents errors that occur during application execution.To browse the .NET Framework source code fo...
Definition: Exception.cs:22
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition: IEquatable.cs:6
override bool Equals(object obj)
Returns a value that indicates whether this T:System.Runtime.Versioning.FrameworkName instance repres...
Specifies that the class can be serialized.
object Clone()
Returns a new T:System.Version object whose value is the same as the current T:System....
Definition: Version.cs:277
override int GetHashCode()
Returns the hash code for the T:System.Runtime.Versioning.FrameworkName object.
Represents the name of a version of the .NET Framework.
Definition: FrameworkName.cs:8