Skip to content

Commit 7284ed5

Browse files
asbjornuJakeGinnivan
authored andcommitted
Add [ReflectionIgnore] attribute to properties in VersionVariables so it's easier and more consistent to exclude properties that aren't version variables.
1 parent 8d49c7b commit 7284ed5

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/GitVersionCore/OutputVariables/VersionVariables.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,22 @@ public VersionVariables(string major,
8989
public string CommitsSinceVersionSource { get; private set; }
9090
public string CommitsSinceVersionSourcePadded { get; private set; }
9191

92+
[ReflectionIgnore]
9293
public static IEnumerable<string> AvailableVariables
9394
{
9495
get
9596
{
9697
return typeof(VersionVariables)
97-
.GetProperties(BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance)
98+
.GetProperties()
99+
.Where(p => !p.GetCustomAttributes(typeof(ReflectionIgnoreAttribute), false).Any())
98100
.Select(p => p.Name)
99-
.Where(p => p != "AvailableVariables" && p != "Item")
100101
.OrderBy(a => a);
101102
}
102103
}
103104

104105
public string CommitDate { get; set; }
105106

107+
[ReflectionIgnore]
106108
public string this[string variable]
107109
{
108110
get { return (string)typeof(VersionVariables).GetProperty(variable).GetValue(this, null); }
@@ -114,7 +116,7 @@ public IEnumerator<KeyValuePair<string, string>> GetEnumerator()
114116
var type = typeof(string);
115117
return typeof(VersionVariables)
116118
.GetProperties()
117-
.Where(p => p.PropertyType == type && !p.GetIndexParameters().Any())
119+
.Where(p => p.PropertyType == type && !p.GetIndexParameters().Any() && !p.GetCustomAttributes(typeof(ReflectionIgnoreAttribute), false).Any())
118120
.Select(p => new KeyValuePair<string, string>(p.Name, (string)p.GetValue(this, null)))
119121
.GetEnumerator();
120122
}
@@ -155,5 +157,10 @@ public bool ContainsKey(string variable)
155157
{
156158
return typeof(VersionVariables).GetProperty(variable) != null;
157159
}
160+
161+
162+
sealed class ReflectionIgnoreAttribute : Attribute
163+
{
164+
}
158165
}
159166
}

0 commit comments

Comments
 (0)