相关疑难解决方法(0)

我可以用Reflection设置属性值吗?

我知道我的C#类中的属性名称.是否可以使用反射来设置此属性的值?

例如,假设我知道属性的名称string propertyName = "first_name";.并且存在一个名为的财产first_name.我可以用这个字符串设置它吗?

c# reflection

26
推荐指数
1
解决办法
3万
查看次数

C#反思:更新房产价值的最快方法?

这是使用反射更新属性的最快方法吗?假设该属性始终为int:

PropertyInfo counterPropertyInfo = GetProperty();
int value = (int)counterPropertyInfo.GetValue(this, null);
counterPropertyInfo.SetValue(this, value + 1, null);
Run Code Online (Sandbox Code Playgroud)

c# reflection performance properties

17
推荐指数
3
解决办法
2万
查看次数

标签 统计

c# ×2

reflection ×2

performance ×1

properties ×1