wasSharp – Diff between revs 27 and 35
?pathlinks?
Rev 27 | Rev 35 | |||
---|---|---|---|---|
Line 139... | Line 139... | |||
139 | /// <param name="structure">the structure to search</param> |
139 | /// <param name="structure">the structure to search</param> |
|
140 | /// <param name="item">the value of the item to search</param> |
140 | /// <param name="item">the value of the item to search</param> |
|
141 | /// <returns>the description or the empty string</returns> |
141 | /// <returns>the description or the empty string</returns> |
|
142 | public static string GetStructureMemberName<T>(T structure, object item) where T : struct |
142 | public static string GetStructureMemberName<T>(T structure, object item) where T : struct |
|
143 | { |
143 | { |
|
144 | var field = typeof(T).GetRuntimeFields().ToArray() |
144 | var f = typeof(T).GetRuntimeFields(); |
|
- | 145 | var p = typeof(T).GetRuntimeProperties(); |
||
- | 146 | |
||
- | 147 | dynamic r = null; |
||
- | 148 | |
||
- | 149 | if (f != null) |
||
- | 150 | r = f.AsParallel() |
||
145 | .AsParallel().SelectMany(f => f.GetCustomAttributes(typeof(NameAttribute), false), |
151 | .SelectMany(o => o.GetCustomAttributes(typeof(NameAttribute), false), |
|
- | 152 | (o, a) => new { Field = o, Att = a }) |
||
146 | (f, a) => new { Field = f, Att = a }).SingleOrDefault(f => f.Field.GetValue(structure).Equals(item)); |
153 | .SingleOrDefault(q => q.Field.GetValue(structure).Equals(item)); |
|
- | 154 | |
||
- | 155 | if (p != null) |
||
- | 156 | r = p.AsParallel() |
||
- | 157 | .SelectMany(o => o.GetCustomAttributes(typeof(NameAttribute), false), |
||
- | 158 | (o, a) => new { Property = o, Att = a }) |
||
- | 159 | .SingleOrDefault(q => q.Property.GetValue(structure).Equals(item)); |
||
- | 160 | |
||
147 | return field != null ? ((NameAttribute)field.Att).Name : string.Empty; |
161 | return r != null ? ((NameAttribute)r.Att).Name : string.Empty; |
|
148 | } |
162 | } |
|
Line 149... | Line 163... | |||
149 | |
163 | |
|
150 | /////////////////////////////////////////////////////////////////////////// |
164 | /////////////////////////////////////////////////////////////////////////// |
|
151 | // Copyright (C) 2016 Wizardry and Steamworks - License: GNU GPLv3 // |
165 | // Copyright (C) 2016 Wizardry and Steamworks - License: GNU GPLv3 // |