博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
通过反射的方式获取类型中的所有属性
阅读量:4506 次
发布时间:2019-06-08

本文共 739 字,大约阅读时间需要 2 分钟。

  • 解决方案
     通过反射的方式获取类型中的所有属性。
  • 引用命名空间
using System.Reflection;
  • 实体类
public class User  {        private string id;        public string Id { get { return id; } set { id = value; } }        private string name;        public string Name { get { return name; } set { name = value; } }  }
  • 获取方法
private PropertyInfo[] GetPropertyInfoArray()   {        PropertyInfo[] props = null;        try        {             Type type = typeof(User);             object obj = Activator.CreateInstance(type);             props = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);        }        catch (Exception ex)        { }        return props;   } 转自:http://www.cnblogs.com/liusuqi/p/3171963.html

转载于:https://www.cnblogs.com/jhabb/p/3213799.html

你可能感兴趣的文章
Ecstore Nginx Rewrite(去掉链接中的index.php) ECSTORE 伪静态
查看>>
Dash
查看>>
BZOJ 1876: [SDOI2009]SuperGCD
查看>>
swift初学日志
查看>>
CCF真题之出现次数最多的数
查看>>
Eclipse上GIT插件_客户端配置
查看>>
使用HANA Web-based Development Workbench创建最简单的Server Side JavaScript
查看>>
JavaScript浏览器对象之二Document对象
查看>>
算法导论 第二部分——排序和顺序统计量
查看>>
监督学习——AdaBoost元算法提高分类性能
查看>>
SharePoint 使用代码创建 SPWeb/SPSiite/SPWebApplication以及WebPart添加到页面与删除 (三)...
查看>>
[原创]在Linux系统Ubuntu14.04上安装部署docker。
查看>>
网络对抗技术 实验四
查看>>
关联Anaconda和最新Pycharm2018.3.2
查看>>
DataGridView列的宽度、行的高度自动调整
查看>>
内部网关协议 (IGP)
查看>>
概要文档知识补遗
查看>>
在Linux上创建webrev[基于git]
查看>>
mybatis缓存
查看>>
幂等性的实现方案
查看>>