.net 读取实体属性和描述注释
class Program
{
static void Main(string[] args)
{
TEST test = new TEST();
test.MyName = "zhangkeyi";
//PropertyInfo[] peroperties = typeof(TEST).GetProperties(BindingFlags.Public | BindingFlags.Instance);
PropertyInfo[] peroperties = (((object)test).GetType()).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("名称")]
public string MyName
{
get;
set;
}
}