using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace ConsoleApplication1
{
class Program
{
//实体类信息复制
public static void EntityToEntity<T>(T pTargetObjSrc, T pTargetObjDest)
{
try
{
foreach (var mItem in typeof(T).GetProperties())
{
mItem.SetValue(pTargetObjDest, mItem.GetValue(pTargetObjSrc, new object[] { }), null);
}
}
catch (NullReferenceException NullEx)
{
throw NullEx;
}
catch (Exception Ex)
{
throw Ex;
}
}
static void Main(string[] args)
{
MyClass obj = new MyClass();
Type t = typeof(MyClass);
int i = ;
obj.five = ;
foreach (var item in t.GetProperties())
{
//设置实体类属性值
item.SetValue(obj, item.GetValue(obj, new object[] { }), null);
i += ;
}
StringBuilder sb = new StringBuilder(); foreach (var item in t.GetProperties())
{
object[] attrs = item.GetCustomAttributes(typeof(System.ComponentModel.DisplayNameAttribute), true);
if (attrs.Length > )
{
string attributename = (attrs[] as System.ComponentModel.DisplayNameAttribute).DisplayName;
sb.Append("类型:" + item.PropertyType.FullName +attributename+ ":" + item.Name + "值:" + item.GetValue(obj, null) + "");
}
}
string result = sb.ToString();
//读取实体类所有信息
Console.Write(result);
}
}
public class MyClass
{
[System.ComponentModel.DisplayName("一")]
public int one
{
set;
get;
}
[System.ComponentModel.DisplayName("二")]
public int two
{
set;
get;
}
[System.ComponentModel.DisplayName("五")]
public int five
{
set;
get;
}
[System.ComponentModel.DisplayName("三")]
public int three
{
set;
get;
}
[System.ComponentModel.DisplayName("四")]
public int four
{
set;
get;
}
}
}

最新文章

  1. 关于java中创建文件,并且写入内容
  2. 关于HTML+CSS设置图片居中的方法
  3. noi 9265 取数游戏
  4. Java反射机制练习(增强可扩展性)
  5. 错误:类Byte是公共的,应在名为Byte.java 的文件中声明public class Byte{}一个错误
  6. [置顶] WEBSOKET服务器搭建
  7. 1bpp像素遍历(找了半天,感谢github)
  8. spring mvc 资源包的映射
  9. Struts2拦截器登录验证
  10. BZOJ 3697: 采药人的路径 [点分治] [我想上化学课]
  11. CodeForces 1151E Number of Components
  12. 问题解决:Spyder不支持OpenCV模块代码提示
  13. codeforces 803D Magazine Ad(二分+贪心)
  14. windows10创建ftp服务器
  15. CSS3 过渡动画
  16. DOM操作之获取HTML、文本和值
  17. 01:zabbix监控redis
  18. git学习------>Git 分支管理最佳实践
  19. java中静态变量与静态方法的继承(转)
  20. HDFS 详解

热门文章

  1. ios开发中APP底部上滑不能调出如WiFi、蓝牙、播放等的设置页面的解决的方法
  2. 2017.7.10 Package name does not correspond to the file path
  3. 对checkpoint not completed的理解
  4. Eclipse web项目导入Intellij 并且部署
  5. Android Activity之间经典切换动画
  6. 倍福TwinCAT(贝福Beckhoff)基础教程 松下官方软件开启报错伺服未就绪怎么办
  7. python数据类型整理
  8. 冰点文库下载器V3.1.4
  9. ubuntu+tomcat,多环境、自动化部署脚本,git+maven+tomcat+ubuntu
  10. mongo: 索引