R
Robert Zurer
This method works but FxCop rightly complains
"Generic methods should provide type parameter"
http://www.gotdotnet.com/team/fxcop/docs/rules.aspx?version=1.32
&url=/Design/GenericMethodsShouldProvideTypeParameter.html
public sealed class ReflectionAgent
{
public static T GetCustomAttribute<T>(MemberInfo memberInfo)
{
if (memberInfo == null) return default(T);
object[] attributes = memberInfo.GetCustomAttributes(typeof(T), true);
return ((attributes != null) && (attributes.Length == 1)) ?
(T)attributes[0] : default(T);
}
}
I want to call it like this
PropertyInfo propInfo = typeof(TestClass).GetProperty("FirstName");
ItemTypeAttribute attr =
ReflectionAgent.GetCustomAttribute<ItemTypeAttribute>(propInfo);
TIA
Robert Zurer
"Generic methods should provide type parameter"
http://www.gotdotnet.com/team/fxcop/docs/rules.aspx?version=1.32
&url=/Design/GenericMethodsShouldProvideTypeParameter.html
public sealed class ReflectionAgent
{
public static T GetCustomAttribute<T>(MemberInfo memberInfo)
{
if (memberInfo == null) return default(T);
object[] attributes = memberInfo.GetCustomAttributes(typeof(T), true);
return ((attributes != null) && (attributes.Length == 1)) ?
(T)attributes[0] : default(T);
}
}
I want to call it like this
PropertyInfo propInfo = typeof(TestClass).GetProperty("FirstName");
ItemTypeAttribute attr =
ReflectionAgent.GetCustomAttribute<ItemTypeAttribute>(propInfo);
TIA
Robert Zurer