我有一个方法,输入类名,通过反射去获取该类所有实体的数据,
但数据都放在object中返回,
private object GetEntities(string fullClassName)
{
Type bllType = this.GetClassType(fullClassName);
Object result = null;
Object obj = Activator.CreateInstance(bllType);
result = bllType.InvokeMember("GetEntities", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance, null, obj,null);
return result;
}
。返回来后不知道怎么把此object转换成dataTable来使用
但数据都放在object中返回,
private object GetEntities(string fullClassName)
{
Type bllType = this.GetClassType(fullClassName);
Object result = null;
Object obj = Activator.CreateInstance(bllType);
result = bllType.InvokeMember("GetEntities", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance, null, obj,null);
return result;
}
。返回来后不知道怎么把此object转换成dataTable来使用
解决方案 »
- 求解
- winform如何動態創建多個panel?
- C#进度条
- linq to sql的动态查询 如何实现 in
- 一个怪异线程问题
- sqlServer中image字段如何追加数据?
- 写Socket时候发现错误提示“不能做任何连接,因为目标机器积极地拒绝它”,不知道原因是什么
- c#程序在98下运行出现 sqlserver does not exist or access denied,是怎么回事,mdac2.8,framework都装过了
- 谁能告诉我c#的强项是什么?数据库?底层好象不行了吧?时时性好象也不行你们都在做什么开发?我不是指的用来做ASP.NET.(我原来用delphi,
- 垃圾回收!!!怎样回收这些东西呢?
- 求助 如何分割数组
- C#连接oracle,诡异的ora-12154错误
DateTable tb = (DateTable)0
{
//创建属性的集合
List<PropertyInfo> pList = new List<PropertyInfo>();
Type type = typeof(TResult);
DataTable dt = new DataTable();
Array.ForEach<PropertyInfo>(type.GetProperties(), p => { pList.Add(p);dt.Columns.Add(p.Name, p.PropertyType); });
foreach (var item in value)
{
//创建一个DataRow实例
DataRow row = dt.NewRow();
pList.ForEach(p => row[p.Name] = p.GetValue(item, null));
dt.Rows.Add(row);
}
return dt;
}
}