/Reflection.cs |
@@ -22,7 +22,7 @@ |
/// <returns>an attribute of type T</returns> |
public static T GetAttributeFromEnumValue<T>(Enum value) where T : Attribute |
{ |
return (T) value.GetType() |
return (T)value.GetType() |
.GetRuntimeField(value.ToString()) |
.GetCustomAttributes(typeof(T), false) |
.SingleOrDefault(); |
@@ -40,7 +40,7 @@ |
{ |
return e.GetType().GetRuntimeFields().ToArray() |
.AsParallel() |
.Select(o => GetAttributeFromEnumValue<T>((Enum) o.GetValue(Activator.CreateInstance<T>()))); |
.Select(o => GetAttributeFromEnumValue<T>((Enum)o.GetValue(Activator.CreateInstance<T>()))); |
} |
|
/////////////////////////////////////////////////////////////////////////// |
@@ -70,7 +70,7 @@ |
/// <returns>the values of the enumeration</returns> |
public static IEnumerable<T> GetEnumValues<T>() |
{ |
return Enum.GetValues(typeof(T)).Cast<object>().Select(value => (T) value); |
return Enum.GetValues(typeof(T)).Cast<object>().Select(value => (T)value); |
} |
|
/////////////////////////////////////////////////////////////////////////// |
@@ -123,10 +123,10 @@ |
var field = typeof(T).GetRuntimeFields().ToArray() |
.AsParallel().SelectMany(f => f.GetCustomAttributes( |
typeof(NameAttribute), false), ( |
f, a) => new {Field = f, Att = a}) |
.SingleOrDefault(a => String.Equals(((NameAttribute) a.Att) |
f, a) => new { Field = f, Att = a }) |
.SingleOrDefault(a => string.Equals(((NameAttribute)a.Att) |
.Name, name, comparison)); |
return field != null ? (T) field.Field.GetValue(Activator.CreateInstance<T>()) : default(T); |
return field != null ? (T)field.Field.GetValue(Activator.CreateInstance<T>()) : default(T); |
} |
|
/////////////////////////////////////////////////////////////////////////// |
@@ -143,8 +143,8 @@ |
{ |
var field = typeof(T).GetRuntimeFields().ToArray() |
.AsParallel().SelectMany(f => f.GetCustomAttributes(typeof(NameAttribute), false), |
(f, a) => new {Field = f, Att = a}).SingleOrDefault(f => f.Field.GetValue(structure).Equals(item)); |
return field != null ? ((NameAttribute) field.Att).Name : string.Empty; |
(f, a) => new { Field = f, Att = a }).SingleOrDefault(f => f.Field.GetValue(structure).Equals(item)); |
return field != null ? ((NameAttribute)field.Att).Name : string.Empty; |
} |
|
/////////////////////////////////////////////////////////////////////////// |
@@ -285,4 +285,4 @@ |
public string Description => description; |
} |
} |
} |
} |