日期:2014-05-17 浏览次数:20491 次
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;
}
}
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)
{
//额外属性
}
}