遍历类的属性
- 博客分类:
- .net
Response.Write(getProperties(l1.Quote)); //项目中的代码。这样也没有遍历所有的 属性的属性吧,,
public string getProperties<T>(T t)
{
string tStr = string.Empty;
if (t == null)
{
return tStr;
}
System.Reflection.PropertyInfo[] properties = t.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
{
string tStr = string.Empty;
if (t == null)
{
return tStr;
}
System.Reflection.PropertyInfo[] properties = t.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
if (properties.Length <= 0)
{
return tStr;
}
foreach (System.Reflection.PropertyInfo item in properties)
{
string name = item.Name;
object value = item.GetValue(t, null);
if (item.PropertyType.IsValueType || item.PropertyType.Name.StartsWith("String"))
{
tStr += string.Format("{0}:{1},", name, value);
}
else
{
getProperties(value);
}
}
return tStr;
}
{
return tStr;
}
foreach (System.Reflection.PropertyInfo item in properties)
{
string name = item.Name;
object value = item.GetValue(t, null);
if (item.PropertyType.IsValueType || item.PropertyType.Name.StartsWith("String"))
{
tStr += string.Format("{0}:{1},", name, value);
}
else
{
getProperties(value);
}
}
return tStr;
}
发表评论
-
ipchange
2009-11-23 21:00 659public string ipChange(u ... -
C# excel
2009-09-17 13:09 2165using System; using System. ... -
SqliteHelper
2009-07-27 14:46 1347using System; using Syst ... -
网址收藏
2009-07-23 14:50 698http://www.cnblogs.com/arte ... -
。net常用工具
2009-07-23 14:48 1746ildasm:反编译.net程序; ilasm:编译 ... -
c#生成Excel
2009-07-23 14:45 2543using System;using System.Colle ... -
C#操作Word!
2009-07-23 14:44 3777using System; using System.Com ... -
验证控件网页代码分析2
2009-07-23 14:43 938还有一个子程序是更新整个页面的验证状态: //更新整个页面 ... -
验证控件网页代码分析
2009-07-23 14:38 1531如果我们在文本框中什么都没有输入,直接点击按钮,则激发Butt ... -
ASP.Net 向xml文件中添加数据(insert操作)
2009-07-23 14:33 1009try { ... -
xml操作
2009-07-23 14:32 698using System; using System.Xml ... -
ip地址转换
2009-07-23 14:30 1104public String getIp(long ip10) ... -
BASE64加密解密
2009-07-23 14:28 788string base64EncodeChars = & ... -
winform Splash加载窗口
2009-07-23 14:28 1867static ApplicationContext conte ... -
C#实现快捷键(系统热键)响应
2009-07-23 14:27 1880C#实现快捷键(系统热键)响应 在应用中,我们可能会需要 ... -
WinForm的一些常用技巧
2009-07-23 14:22 2179在任务栏不显示 将WinForm的ShowInT ... -
去除文本中的标签
2009-07-23 14:10 736/// <summary> / ... -
C#验证码
2009-07-23 14:03 1243using System; using System.Dra ... -
des和RSA两种加密方式的例子
2009-07-23 13:50 1309static public string RSA_Encry ...
相关推荐
利用runtime的class_copyPropertyList方法获取类的属性名字,以前老的代码不能用,新版的注意事项已经加到注释连了,yyModel框架也是利用这种方法遍历类属性
C#遍历类的属性,这个主要用到C#的反射,该技术是每个开发者必备的,必须熟悉,可以信手拈来的技能,熟练后,让你以后的开发之旅,一路靓丽。
遍历类里面的属性 OC语言可以遍历类中的所有属性和值
c#遍历obj属性用例,非常实用的文档 网络搜集
所有在反序列化Json字符串时需要一种通用的转换方式,而不是写死的某个类的反序列化,这里介绍的一种思路就是使用dynamic关键字来实现通用反序列化并比较反序列化后的对象是否深度相等即比较对象的各个字段是否相等...
昨天因为公司的一个需求,所以就研究了一下json对象的属性的遍历和动态修改: var person= { name: 'zhangsan', pass: '123' , 'sni.ni' : 'sss', hello:function (){ ...//遍历属性 for(var ite
安装使用操作简单,读取数据后,可逐条记录对数据进行浏览,窗口自动定位,且视图大小固定
java 枚举遍历键值对 属性类Properties 类加载器
教你如何使用CE人物属性.图文教程,简单明了~
qt 实现xml的完整操作 遍历属性等 非常实用 项目中多次用
Object.keys() 方法会返回一个由一个给定对象的自身可枚举属性组成的数组,数组中属性名的排列顺序和使用 for…in 循环遍历该对象时返回的顺序一致 。如果对象的键-值都不可枚举,那么将返回由键组成的数组。 这是...
NULL 博文链接:https://linleizi.iteye.com/blog/1722171
下面小编就为大家带来一篇java反射遍历实体类属性和类型,并赋值和获取值的简单方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
计算机前端-核心编程.视频08遍历对象属性.avi
NULL 博文链接:https://jinhailion.iteye.com/blog/1530966
地理信息或测绘行业根据arcgis属性便利各要素,无需点开属性列表,自己写的arcgis小插件,无需安装。
jQuery 1.5 遍历xml节点属性源码,请参照博客文章http://blog.csdn.net/Pipi0714/archive/2011/02/16/6187357.aspx
首先新建一个实体类Person @Data public class Person { /** 编码 */ private String code; /** 名字 */ private String name; public Person(String code, String name) { this.code = code; this.name = ...
对应某个类的实例化的对象tc, 遍历获取所有属性(子成员)的方法(采用反射): 代码如下: Type t = tc.GetType();//获得该类的Type //再用Type.GetProperties获得PropertyInfo[],然后就可以用foreach 遍历了 foreach ...
使用arcpy 遍历某文件下(包括子文件夹)所有面要素类,然后将这些要素合并。