3
3
using System . Collections ;
4
4
using System . Collections . Generic ;
5
5
using System . Linq ;
6
+ using System . Reflection ;
6
7
7
8
public class VersionVariables : IEnumerable < KeyValuePair < string , string > >
8
9
{
9
- public VersionVariables ( string major , string minor , string patch , string buildMetaData , string buildMetaDataPadded , string fullBuildMetaData , string branchName , string sha , string majorMinorPatch , string semVer , string legacySemVer , string legacySemVerPadded , string fullSemVer , string assemblySemVer , string preReleaseTag , string preReleaseTagWithDash , string informationalVersion ,
10
- string commitDate , string nugetVersion , string nugetVersionV2 , string commitsSinceVersionSource , string commitsSinceVersionSourcePadded )
10
+ public VersionVariables ( string major ,
11
+ string minor ,
12
+ string patch ,
13
+ string buildMetaData ,
14
+ string buildMetaDataPadded ,
15
+ string fullBuildMetaData ,
16
+ string branchName ,
17
+ string sha ,
18
+ string majorMinorPatch ,
19
+ string semVer ,
20
+ string legacySemVer ,
21
+ string legacySemVerPadded ,
22
+ string fullSemVer ,
23
+ string assemblySemVer ,
24
+ string preReleaseTag ,
25
+ string preReleaseTagWithDash ,
26
+ string informationalVersion ,
27
+ string commitDate ,
28
+ string nugetVersion ,
29
+ string nugetVersionV2 ,
30
+ string commitsSinceVersionSource ,
31
+ string commitsSinceVersionSourcePadded )
11
32
{
12
33
Major = major ;
13
34
Minor = minor ;
@@ -33,6 +54,7 @@ public VersionVariables(string major, string minor, string patch, string buildMe
33
54
CommitsSinceVersionSourcePadded = commitsSinceVersionSourcePadded ;
34
55
}
35
56
57
+
36
58
public string Major { get ; private set ; }
37
59
public string Minor { get ; private set ; }
38
60
public string Patch { get ; private set ; }
@@ -57,30 +79,40 @@ public VersionVariables(string major, string minor, string patch, string buildMe
57
79
58
80
public static IEnumerable < string > AvailableVariables
59
81
{
60
- get { return typeof ( VersionVariables ) . GetProperties ( ) . Select ( p => p . Name ) . OrderBy ( a => a ) ; }
82
+ get
83
+ {
84
+ return typeof ( VersionVariables )
85
+ . GetProperties ( BindingFlags . Public | BindingFlags . DeclaredOnly | BindingFlags . Instance )
86
+ . Select ( p => p . Name )
87
+ . Where ( p => p != "AvailableVariables" && p != "Item" )
88
+ . OrderBy ( a => a ) ;
89
+ }
61
90
}
62
91
63
92
public string CommitDate { get ; set ; }
64
93
94
+ public string this [ string variable ]
95
+ {
96
+ get { return ( string ) typeof ( VersionVariables ) . GetProperty ( variable ) . GetValue ( this , null ) ; }
97
+ }
98
+
99
+
65
100
public IEnumerator < KeyValuePair < string , string > > GetEnumerator ( )
66
101
{
67
102
var type = typeof ( string ) ;
68
103
return typeof ( VersionVariables )
69
104
. GetProperties ( )
70
105
. Where ( p => p . PropertyType == type && ! p . GetIndexParameters ( ) . Any ( ) )
71
- . Select ( p => new KeyValuePair < string , string > ( p . Name , ( string ) p . GetValue ( this , null ) ) )
106
+ . Select ( p => new KeyValuePair < string , string > ( p . Name , ( string ) p . GetValue ( this , null ) ) )
72
107
. GetEnumerator ( ) ;
73
108
}
74
109
110
+
75
111
IEnumerator IEnumerable . GetEnumerator ( )
76
112
{
77
113
return GetEnumerator ( ) ;
78
114
}
79
115
80
- public string this [ string variable ]
81
- {
82
- get { return ( string ) typeof ( VersionVariables ) . GetProperty ( variable ) . GetValue ( this , null ) ; }
83
- }
84
116
85
117
public bool TryGetValue ( string variable , out string variableValue )
86
118
{
@@ -94,6 +126,7 @@ public bool TryGetValue(string variable, out string variableValue)
94
126
return false ;
95
127
}
96
128
129
+
97
130
public bool ContainsKey ( string variable )
98
131
{
99
132
return typeof ( VersionVariables ) . GetProperty ( variable ) != null ;
0 commit comments