假设我有一个有3个属性的类。直到运行时我才知道要读取哪个属性。有没有办法在不使用switch/if-else语句的情况下做到这一点?
如果将DataTable视为一个类,那么可以动态地处理列,这是可行的,但我无法将我的类更改为DataTable (长篇大论)。
对于DataTable,代码为:
string columnName = "Age";
int age = dataRow[columnName];这在类中是怎么可能的?
string propertyName = "Baka";
int age = item.getProperty(propertyName) // ???发布于 2009-11-19 05:08:17
string propertyToGet = "SomeProperty";
SomeClass anObject = new SomeClass();
string propertyValue =
(string)typeof(SomeClass)
.GetProperty("SomeProperty")
.GetValue(anObject, null);https://stackoverflow.com/questions/1759026
复制相似问题