As far as I know, you should get the attribute from the field. You should use:
var field = typeof(Header).GetField(value.ToString()); var old = field.IsDefined(typeof(OldProtocolAttribute), false);
Or to get the whole array:
var attributeType = typeof(OldProtocolAttribute); var array = typeof(Header).GetFields(BindingFlags.Public | BindingFlags.Static) .Where(field => field.IsDefined(attributeType, false)) .Select(field => (Header) field.GetValue(null)) .ToArray();
Obviously, if you need it often, you might want to cache the results.
Jon skeet
source share