wasSharp
/Reflection.cs |
@@ -141,10 +141,24 @@ |
/// <returns>the description or the empty string</returns> |
public static string GetStructureMemberName<T>(T structure, object item) where T : struct |
{ |
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; |
var f = typeof(T).GetRuntimeFields(); |
var p = typeof(T).GetRuntimeProperties(); |
|
dynamic r = null; |
|
if (f != null) |
r = f.AsParallel() |
.SelectMany(o => o.GetCustomAttributes(typeof(NameAttribute), false), |
(o, a) => new { Field = o, Att = a }) |
.SingleOrDefault(q => q.Field.GetValue(structure).Equals(item)); |
|
if (p != null) |
r = p.AsParallel() |
.SelectMany(o => o.GetCustomAttributes(typeof(NameAttribute), false), |
(o, a) => new { Property = o, Att = a }) |
.SingleOrDefault(q => q.Property.GetValue(structure).Equals(item)); |
|
return r != null ? ((NameAttribute)r.Att).Name : string.Empty; |
} |
|
/////////////////////////////////////////////////////////////////////////// |