转 http://bbs.csdn.net/topics/350019800
PropertyInfo[] peroperties = typeof(TEST).GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (PropertyInfo property in peroperties)
{
object[] objs = property.GetCustomAttributes(typeof(DescriptionAttribute), true);
if (objs.Length > 0)
{
Console.WriteLine("{0}: {1}", property.Name, ((DescriptionAttribute)objs[0]).Description);
}
}
Console.ReadKey();
class TEST
{
[Description("a")]
public string X
{
get { return null; }
}
}