使用Reflection
To set a property value using reflection, follow these steps:
Get the PropertyInfo Object:Use Type.GetProperty to retrieve the PropertyInfo object associated with the property you want to modify.如果属性不是公开的,则可能需要指定其他绑定标志,例如bindingflags.nonpublic或bindingflags.instance。
一旦拥有propertyInfo对象,请调用其setValue方法实际设置了该属性的值。此方法采用两个参数:您要修改的对象实例和要设置的新值。免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。
Copyright© 2022 湘ICP备2022001581号-3