I am trying to convert the following method (which works fine in the .NET Framework 4.6.2) to .NET Core 1.1.
public static TAttribute GetCustomAttribute<TAttribute>(MemberInfo member) where TAttribute : Attribute
{
var attr = System.Attribute.GetCustomAttribute(member, typeof(TAttribute));
if (attr is TAttribute)
return attr;
else
return null;
}
This code gives me an error
The attribute does not contain a definition for GetCustomAttribute.
Any idea what the equivalent of .NET Core should be?
PS I tried the following, but it seems to be an exception. Not sure what the exception is, because it just stops the application. I tried to put the code in a block try catch, but still it just stops working, so I cannot catch an exception.
public static TAttribute GetCustomAttribute<TAttribute>(MemberInfo member) where TAttribute : Attribute
{
var attr = GetCustomAttribute<TAttribute>(member);
if (attr is TAttribute)
return attr;
else
return null;
}
source
share