0 c# reflection properties object
我如何动态地引用Employee类型对象的属性?我喜欢什么employee."hasBeenPaid"?它涉及反思吗?
class Employee
{
String name;
Bool hasBeenPaid;
}
Run Code Online (Sandbox Code Playgroud)
你可以尝试:
Type type = your_class.GetType();
PropertyInfo propinfo = type.GetProperty("hasBeenPaid");
Run Code Online (Sandbox Code Playgroud)
如果你需要这个价值
value = propinfo.GetValue(your_class, null);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
227 次 |
| 最近记录: |