public class Testcls
{
public string strName { get; set; }
}
Testcls itm = new Testcls();itm.GetType().InvokeMember("strName", System.Reflection.BindingFlags.SetProperty, null, itm, new object[] { 22 });
始终报告 未找到方法
什么问题,怎么解决?反射
{
public string strName { get; set; }
}
Testcls itm = new Testcls();itm.GetType().InvokeMember("strName", System.Reflection.BindingFlags.SetProperty, null, itm, new object[] { 22 });
始终报告 未找到方法
什么问题,怎么解决?反射
应该就可以了。
itm.GetType().GetProperty("strName").SetValue(itm, "22");
这个方法行不通,strName 是举例的,实际类型不确定
object obj = new object();
obj = 22;
itm.GetType().GetProperty("strName").SetValue(itm, obj, null);这样,直接就报错了我要从别的地方读取值,用foreach (PropertyInfo p in itm.GetProperties())放到属性里面,没法确定属性的类型的