zoukankan      html  css  js  c++  java
  • 学习日记17,、、通过反射获取model实体属性display的值

    本来是想到网上直接找个用的,但是找的一些都不是我想要的,然后就参考自己摸索写了一个

    这里的UserModel是我自己定义的一个实体类,代码就不用放出来了

    var t = typeof(UserModel);
    PropertyInfo[] propertyList = t.GetProperties();
    foreach(PropertyInfo item in propertyList)
    {
    //Console.WriteLine(item.Attributes);
    //Console.WriteLine(item.CustomAttributes);
    Console.WriteLine(item.Name);
    Console.WriteLine(t.GetProperty(item.Name).GetCustomAttribute<DisplayAttribute>().Name);
    }
    Console.ReadLine();

  • 相关阅读:
    python二进制转换
    git的使用
    c++primer plus笔记
    c++primer 学习笔记
    二分查找
    字符串全排列
    斐波那契数列
    JavaScript 相关
    HTTP记录
    前端笔记
  • 原文地址:https://www.cnblogs.com/Wxinchun/p/8763495.html
Copyright © 2011-2022 走看看