10 [__DynamicallyInvokable]
13 internal enum ParseFailureKind
21 internal struct VersionResult
23 internal Version m_parsedVersion;
25 internal ParseFailureKind m_failure;
27 internal string m_exceptionArgument;
29 internal string m_argumentName;
31 internal bool m_canThrow;
33 internal void Init(
string argumentName,
bool canThrow)
35 m_canThrow = canThrow;
36 m_argumentName = argumentName;
39 internal void SetFailure(ParseFailureKind failure)
41 SetFailure(failure,
string.Empty);
44 internal void SetFailure(ParseFailureKind failure,
string argument)
47 m_exceptionArgument = argument;
50 throw GetVersionParseException();
54 internal Exception GetVersionParseException()
58 case ParseFailureKind.ArgumentNullException:
60 case ParseFailureKind.ArgumentException:
62 case ParseFailureKind.ArgumentOutOfRangeException:
64 case ParseFailureKind.FormatException:
88 private int _Build = -1;
90 private int _Revision = -1;
92 private static readonly
char[] SeparatorsArray =
new char[1]
97 private const int ZERO_CHAR_VALUE = 48;
101 [__DynamicallyInvokable]
104 [__DynamicallyInvokable]
113 [__DynamicallyInvokable]
116 [__DynamicallyInvokable]
125 [__DynamicallyInvokable]
128 [__DynamicallyInvokable]
137 [__DynamicallyInvokable]
140 [__DynamicallyInvokable]
149 [__DynamicallyInvokable]
152 [__DynamicallyInvokable]
155 return (
short)(_Revision >> 16);
161 [__DynamicallyInvokable]
164 [__DynamicallyInvokable]
167 return (
short)(_Revision & 0xFFFF);
178 [__DynamicallyInvokable]
179 public Version(
int major,
int minor,
int build,
int revision)
200 _Revision = revision;
209 [__DynamicallyInvokable]
210 public Version(
int major,
int minor,
int build)
234 [__DynamicallyInvokable]
258 [__DynamicallyInvokable]
262 _Major = version2.
Major;
263 _Minor = version2.
Minor;
264 _Build = version2.
Build;
280 version._Major = _Major;
281 version._Minor = _Minor;
282 version._Build = _Build;
283 version._Revision = _Revision;
300 if (version2 ==
null)
304 if (_Major != version2._Major)
306 if (_Major > version2._Major)
312 if (_Minor != version2._Minor)
314 if (_Minor > version2._Minor)
320 if (_Build != version2._Build)
322 if (_Build > version2._Build)
328 if (_Revision != version2._Revision)
330 if (_Revision > version2._Revision)
343 [__DynamicallyInvokable]
350 if (_Major != value._Major)
352 if (_Major > value._Major)
358 if (_Minor != value._Minor)
360 if (_Minor > value._Minor)
366 if (_Build != value._Build)
368 if (_Build > value._Build)
374 if (_Revision != value._Revision)
376 if (_Revision > value._Revision)
389 [__DynamicallyInvokable]
397 if (_Major != version._Major || _Minor != version._Minor || _Build != version._Build || _Revision != version._Revision)
408 [__DynamicallyInvokable]
415 if (_Major != obj._Major || _Minor != obj._Minor || _Build != obj._Build || _Revision != obj._Revision)
424 [__DynamicallyInvokable]
428 num |= (_Major & 0xF) << 28;
429 num |= (_Minor & 0xFF) << 20;
430 num |= (_Build & 0xFF) << 12;
431 return num | (_Revision & 0xFFF);
436 [__DynamicallyInvokable]
456 [__DynamicallyInvokable]
464 return _Major.ToString();
468 AppendPositiveNumber(_Major, stringBuilder);
469 stringBuilder.
Append(
'.');
470 AppendPositiveNumber(_Minor, stringBuilder);
471 return StringBuilderCache.GetStringAndRelease(stringBuilder);
481 AppendPositiveNumber(_Major, stringBuilder);
482 stringBuilder.
Append(
'.');
483 AppendPositiveNumber(_Minor, stringBuilder);
484 stringBuilder.
Append(
'.');
485 AppendPositiveNumber(_Build, stringBuilder);
486 return StringBuilderCache.GetStringAndRelease(stringBuilder);
495 AppendPositiveNumber(_Major, stringBuilder);
496 stringBuilder.
Append(
'.');
497 AppendPositiveNumber(_Minor, stringBuilder);
498 stringBuilder.
Append(
'.');
499 AppendPositiveNumber(_Build, stringBuilder);
500 stringBuilder.
Append(
'.');
501 AppendPositiveNumber(_Revision, stringBuilder);
502 return StringBuilderCache.GetStringAndRelease(stringBuilder);
508 private static void AppendPositiveNumber(
int num,
StringBuilder sb)
515 sb.
Insert(length, (
char)(48 + num2));
530 [__DynamicallyInvokable]
537 VersionResult result =
default(VersionResult);
538 result.Init(
"input", canThrow:
true);
539 if (!TryParseVersion(input, ref result))
541 throw result.GetVersionParseException();
543 return result.m_parsedVersion;
551 [__DynamicallyInvokable]
554 VersionResult result2 =
default(VersionResult);
555 result2.Init(
"input", canThrow:
false);
556 bool result3 = TryParseVersion(input, ref result2);
557 result = result2.m_parsedVersion;
561 private static bool TryParseVersion(
string version, ref VersionResult result)
565 result.SetFailure(ParseFailureKind.ArgumentNullException);
568 string[] array = version.Split(SeparatorsArray);
569 int num = array.Length;
570 if (num < 2 || num > 4)
572 result.SetFailure(ParseFailureKind.ArgumentException);
575 if (!TryParseComponent(array[0],
"version", ref result, out
int parsedComponent))
579 if (!TryParseComponent(array[1],
"version", ref result, out
int parsedComponent2))
586 if (!TryParseComponent(array[2],
"build", ref result, out
int parsedComponent3))
593 if (!TryParseComponent(array[3],
"revision", ref result, out
int parsedComponent4))
597 result.m_parsedVersion =
new Version(parsedComponent, parsedComponent2, parsedComponent3, parsedComponent4);
601 result.m_parsedVersion =
new Version(parsedComponent, parsedComponent2, parsedComponent3);
606 result.m_parsedVersion =
new Version(parsedComponent, parsedComponent2);
611 private static bool TryParseComponent(
string component,
string componentName, ref VersionResult result, out
int parsedComponent)
615 result.SetFailure(ParseFailureKind.FormatException, component);
618 if (parsedComponent < 0)
620 result.SetFailure(ParseFailureKind.ArgumentOutOfRangeException, componentName);
631 [__DynamicallyInvokable]
634 return v1?.
Equals(v2) ?? ((object)v2 ==
null);
642 [__DynamicallyInvokable]
655 [__DynamicallyInvokable]
658 if ((
object)v1 ==
null)
672 [__DynamicallyInvokable]
675 if ((
object)v1 ==
null)
687 [__DynamicallyInvokable]
698 [__DynamicallyInvokable]
static CultureInfo InvariantCulture
Gets the T:System.Globalization.CultureInfo object that is culture-independent (invariant).
Version(int major, int minor)
Initializes a new instance of the T:System.Version class using the specified major and minor values.
override int GetHashCode()
Returns a hash code for the current T:System.Version object.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
static bool operator >=(Version v1, Version v2)
Determines whether the first specified T:System.Version object is greater than or equal to the second...
bool Equals(Version obj)
Returns a value indicating whether the current T:System.Version object and a specified T:System....
int CompareTo(object version)
Compares the current T:System.Version object to a specified object and returns an indication of their...
unsafe StringBuilder Insert(int index, string value, int count)
Inserts one or more copies of a specified string into this instance at the specified character positi...
int CompareTo(Version value)
Compares the current T:System.Version object to a specified T:System.Version object and returns an in...
static bool operator >(Version v1, Version v2)
Determines whether the first specified T:System.Version object is greater than the second specified T...
override bool Equals(object obj)
Returns a value indicating whether the current T:System.Version object is equal to a specified object...
The exception that is thrown when the value of an argument is outside the allowable range of values a...
static bool operator !=(Version v1, Version v2)
Determines whether two specified T:System.Version objects are not equal.
Defines a generalized type-specific comparison method that a value type or class implements to order ...
The exception that is thrown when an arithmetic, casting, or conversion operation in a checked contex...
NumberStyles
Determines the styles permitted in numeric string arguments that are passed to the Parse and TryParse...
Version(string version)
Initializes a new instance of the T:System.Version class using the specified string.
static bool operator<(Version v1, Version v2)
Determines whether the first specified T:System.Version object is less than the second specified T:Sy...
override string ToString()
Converts the value of the current T:System.Version object to its equivalent T:System....
Provides information about, and means to manipulate, the current environment and platform....
StringBuilder Append(char value, int repeatCount)
Appends a specified number of copies of the string representation of a Unicode character to this inst...
int Major
Gets the value of the major component of the version number for the current T:System....
Version(int major, int minor, int build, int revision)
Initializes a new instance of the T:System.Version class with the specified major,...
int Length
Gets or sets the length of the current T:System.Text.StringBuilder object.
Supports cloning, which creates a new instance of a class with the same value as an existing instance...
static bool operator==(Version v1, Version v2)
Determines whether two specified T:System.Version objects are equal.
string ToString(int fieldCount)
Converts the value of the current T:System.Version object to its equivalent T:System....
Represents the version number of an assembly, operating system, or the common language runtime....
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
static Version Parse(string input)
Converts the string representation of a version number to an equivalent T:System.Version object.
The exception that is thrown when one of the arguments provided to a method is not valid.
int Build
Gets the value of the build component of the version number for the current T:System....
short MajorRevision
Gets the high 16 bits of the revision number.
static bool operator<=(Version v1, Version v2)
Determines whether the first specified T:System.Version object is less than or equal to the second T:...
Represents errors that occur during application execution.To browse the .NET Framework source code fo...
int Minor
Gets the value of the minor component of the version number for the current T:System....
Defines a generalized method that a value type or class implements to create a type-specific method f...
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....
Provides information about a specific culture (called a locale for unmanaged code development)....
static bool TryParse(string input, out Version result)
Tries to convert the string representation of a version number to an equivalent T:System....
Version(int major, int minor, int build)
Initializes a new instance of the T:System.Version class using the specified major,...
Version()
Initializes a new instance of the T:System.Version class.
int Revision
Gets the value of the revision component of the version number for the current T:System....
short MinorRevision
Gets the low 16 bits of the revision number.