mercredi 5 avril 2017

System.Attribute.GetCustomAttribute in .NET Core

I'm trying to convert the following method (which works fine in .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 (TAttribute)attr;
    else
       return null;
}

This code is giving me the error

Attribute does not contain a definition for GetCustomAttribute.

Any idea what the .NET Core equivalent of this should be?





Aucun commentaire:

Enregistrer un commentaire