62,073
社区成员
发帖
与我相关
我的任务
分享
public class Model
{
string imgUrl;
[PropertyMappingAttribute(IsCondition=true)]
public string ImgUrl { get; set; }
}
//
public class PropertyMappingAttribute : Attribute
{
[Description("是否是额外属性"),DefaultValue(true)]
public bool IsCondition
{
get;set;
}
}
反射时可以通过PropertyMappingAttribute来判断
Model m=new Model();
PropertyInfo[] pis = m.GetType().GetProperties();
foreach (PropertyInfo pi in pis)
{
PropertyMappingAttribute []attr = (PropertyMappingAttribute[])pi.GetCustomAttributes(typeof(PropertyMappingAttribute),true);
if (attr.Length != 0 && attr[0].IsCondition)
{
//额外属性
}
}