wasSharp
/Reflection.cs |
@@ -115,8 +115,9 @@ |
/// </summary> |
/// <typeparam name="T">the enumeration type</typeparam> |
/// <param name="name">the description of a member</param> |
/// <param name="comparison">the string comparison to use</param> |
/// <returns>the value or the default of T if case no name attribute found</returns> |
public static T GetEnumValueFromName<T>(string name) |
public static T GetEnumValueFromName<T>(string name, StringComparison comparison = StringComparison.OrdinalIgnoreCase) |
{ |
var field = typeof(T).GetRuntimeFields().ToArray() |
.AsParallel().SelectMany(f => f.GetCustomAttributes( |
@@ -123,7 +124,7 @@ |
typeof(NameAttribute), false), ( |
f, a) => new {Field = f, Att = a}) |
.SingleOrDefault(a => Strings.StringEquals(((NameAttribute) a.Att) |
.Name, name, StringComparison.Ordinal)); |
.Name, name, comparison)); |
return field != null ? (T) field.Field.GetValue(Activator.CreateInstance<T>()) : default(T); |
} |
|