假如有如下一个class,我需要对其所有property进行便利取值,
class A
{
private int i;
public int I
{
get{return i;}
set{i = value;}
}
private string s;
public string S
{
get{return s;}
set{s = value;}
}
} foreach (PropertyInfo fi in typeof(A).GetProperties())
{
object value = fi.GetValue(structure, null);
}对string 类型的property进行取值的时候就会出错,这是为什么呢?
class A
{
private int i;
public int I
{
get{return i;}
set{i = value;}
}
private string s;
public string S
{
get{return s;}
set{s = value;}
}
} foreach (PropertyInfo fi in typeof(A).GetProperties())
{
object value = fi.GetValue(structure, null);
}对string 类型的property进行取值的时候就会出错,这是为什么呢?
解决方案 »
- Page.Request.Files.Count问题!
- Visual Studio调试web应用程序
- 有三个三角了,呵呵!散分
- 用c#+AE做数据入库,数据库是Oracle10G,要怎么做?
- C#2005做的winform项目,textBox控件 安装在winXP可输入20汉字,在win98系统只可输入10个汉字什么原因?
- 有关数据适配器的update异常问题,在线等
- datagridview中的数据如何打印出来?
- DataGridView的图片列怎么不显示打红叉
- 点击下一页无数据,提交是POST
- 用C#做ERP項目,規划討論,有興趣進來一聊
- 正则匹配 大侠们帮忙下
- .net里的并行任务Task的生命周期是多少?
{
A structure = new A();
structure.I = 1;
structure.S = "s";
foreach (PropertyInfo fi in typeof(A).GetProperties())
{
object value = fi.GetValue(structure, null);
Console.WriteLine(value);
}
}
class A
{
private int i;
public int I
{
get { return i; }
set { i = value; }
}
private string s;
public string S
{
get { return s; }
set { s = value; }
}
}输出正确,没问题。
..
PropertyInfo[] peroperties = typeof(A).GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (PropertyInfo property in peroperties)
{
object value =property.GetValue(obj, null)
}