How to use reflection in C# to do this job?# Programming - 葵花宝典
b*y
1 楼
Suppose I have a class as follows,
public class C
{
int id;
string name;
double amount;
public void ClassToDatarow(ref datarow r)
{
r["id"] = this.id;
r["name"] = this.name;
r["amount"] = this.amount;
}
}
Class C may have many attributes, every time I make a change to the
attributes I have to do the same to the function. Can I use some iteration
to finish the ClassToDatrow job without writing all r["var"]= this.var?
public class C
{
int id;
string name;
double amount;
public void ClassToDatarow(ref datarow r)
{
r["id"] = this.id;
r["name"] = this.name;
r["amount"] = this.amount;
}
}
Class C may have many attributes, every time I make a change to the
attributes I have to do the same to the function. Can I use some iteration
to finish the ClassToDatrow job without writing all r["var"]= this.var?