就是说 我自己写了一个实体类,我现在要在不知道这个实体类对象具体有多少的属性时,将所有的遍历一边。最终可以知道这个对象的所有属性及值呢?
各位大虾:有想法的就指点指点小妹,小妹感激不尽!
各位大虾:有想法的就指点指点小妹,小妹感激不尽!
解决方案 »
- jquery取数组的值
- 用过jquery放大镜的遇到这种问题没
- (紧急)vs2010 加载dll,运行时报错,任何DLL都一样
- asp.net 的Memcached用法【高分求解】
- 急求:visual studio.net 2005 下载地址!!!
- |M| 请问一下当你们在后台程序里面执行一段代码后要跳转到某个页面的时候是怎么做的
- 紧急求助,服务器端事件如何给客户端的hidden控件设置value值
- 和我相同境遇的兄弟请看过来,各位大侠指点迷津
- 求救,.net 调试时地址栏是乱码问题
- 只灌.NET Framework的 Windows SERVER
- 问大家一个问题。。我已经没有办法了。。
- 又是有关读写EXCEL的问题
PropertyInfo[] pis = typeof(类名).GetProperties();foreach (PropertyInfo pi in pis){var value1 = pi.GetValue(对象名, null);//得到属性的值var attr=pi.Name.ToString()//得到属性的名称}
/// 是否所有的属性不为null
/// </summary>
/// <param name="t"></param>
/// <returns></returns>
public static bool Finished(object t)
{
string tStr = string.Empty;
System.Reflection.PropertyInfo[] properties = t.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
foreach (System.Reflection.PropertyInfo item in properties)
{
string name = item.Name;
object value = item.GetValue(t, null);
if (value == null)
{
return false;
}
}
return true;
}
{property .Name;
property .PropertyType;
}
{
IList <T> lst= new List <T>();
while (reader.Read())
{
T RowInstance = Activator.CreateInstance <T>();
foreach (PropertyInfo Property in typeof(T).GetProperties())
{
foreach (BindingFieldAttribute FieldAttr in Property.GetCustomAttributes(typeof(BindingFieldAttribute), true))
{
try
{
int Ordinal = reader.GetOrdinal(FieldAttr.FieldName);
if (reader.GetValue(Ordinal) != DBNull.Value)
{
Property.SetValue(RowInstance, Convert.ChangeType(reader.GetValue(Ordinal), Property.PropertyType), null);
}
}
catch
{
break;
}
}
}
lst.Add(RowInstance);
}
return lst;
}
{property .Name;
property .PropertyType;
}PropertyInfo 实体层也就是你自己的实体
property 关键字
peroperties 定义的
property .Name; 得到实体的名字
property .PropertyType; 实体的属性
然后你输出就知道了,要不在调试的时候看看你得到的每个属性的值也行