1
+ using GitHub . Logging ;
1
2
using System ;
2
3
using System . Text . RegularExpressions ;
3
4
@@ -7,6 +8,7 @@ public struct TheVersion : IComparable<TheVersion>
7
8
{
8
9
private const string versionRegex = @"(?<major>\d+)(\.?(?<minor>[^.]+))?(\.?(?<patch>[^.]+))?(\.?(?<build>.+))?" ;
9
10
private const int PART_COUNT = 4 ;
11
+ public static TheVersion Default { get ; } = default ( TheVersion ) . Initialize ( null ) ;
10
12
11
13
[ NotSerialized ] private int major ;
12
14
[ NotSerialized ] public int Major { get { Initialize ( Version ) ; return major ; } }
@@ -36,16 +38,13 @@ public struct TheVersion : IComparable<TheVersion>
36
38
37
39
public static TheVersion Parse ( string version )
38
40
{
39
- Guard . ArgumentNotNull ( version , "version" ) ;
40
- TheVersion ret = default ( TheVersion ) ;
41
- ret . Initialize ( version ) ;
42
- return ret ;
41
+ return default ( TheVersion ) . Initialize ( version ) ;
43
42
}
44
43
45
- private void Initialize ( string version )
44
+ private TheVersion Initialize ( string version )
46
45
{
47
46
if ( initialized )
48
- return ;
47
+ return this ;
49
48
50
49
this . Version = version ;
51
50
@@ -58,6 +57,9 @@ private void Initialize(string version)
58
57
special = null ;
59
58
parts = 0 ;
60
59
60
+ if ( String . IsNullOrEmpty ( version ) )
61
+ return this ;
62
+
61
63
intParts = new int [ PART_COUNT ] ;
62
64
stringParts = new string [ PART_COUNT ] ;
63
65
@@ -66,7 +68,10 @@ private void Initialize(string version)
66
68
67
69
var match = regex . Match ( version ) ;
68
70
if ( ! match . Success )
69
- throw new ArgumentException ( "Invalid version: " + version , "version" ) ;
71
+ {
72
+ LogHelper . Error ( new ArgumentException ( "Invalid version: " + version , "version" ) ) ;
73
+ return this ;
74
+ }
70
75
71
76
major = int . Parse ( match . Groups [ "major" ] . Value ) ;
72
77
intParts [ 0 ] = major ;
@@ -125,6 +130,7 @@ private void Initialize(string version)
125
130
isBeta = special . IndexOf ( "beta" ) >= 0 ;
126
131
}
127
132
initialized = true ;
133
+ return this ;
128
134
}
129
135
130
136
public override string ToString ( )
0 commit comments