扩展方式:
public static T GetAttributeFrom<T>(this object instance, string propertyName) where T : Attribute{ var attrType = typeof(T); var property = instance.GetType().GetProperty(propertyName); return (T)property .GetCustomAttributes(attrType, false).First();}码:
var name = player.GetAttributeFrom<DisplayAttribute>(nameof(player.PlayerDescription)).Name;var maxLength = player.GetAttributeFrom<MaxLengthAttribute>(nameof(player.PlayerName)).Length;



