because metadatatype is not for such porposes but you can use this method
private bool PropertyHasAttribute<T>(string properyName, Type attributeType)
{
MetadataTypeAttribute att = (MetadataTypeAttribute)Attribute.GetCustomAttribute(typeof(T), typeof(MetadataTypeAttribute));
if (att != null)
{
;
foreach (var prop in Type.GetType(att.MetadataClassType.UnderlyingSystemType.FullName).GetProperties())
{
if (properyName.ToLower() == properyName.ToLower() && Attribute.IsDefined(prop,attributeType))
return true;
}
}
return false;
}
and you can use like this
bool res = PropertyHasAttribute<ClientInfoView>("Login", typeof(DisplayAttribute))
this tell you that the class property login has or has not displayattribute , but if you need to findout attribute Value you can use Attribute.GetCustomAttribute method and cast it to your selected attribute like display attribute and read Name property by .Name :)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…