在对象初始化之前使用反射设置静态变量值?
无论如何,是否可以在尚未初始化的对象上设置静态(私有)变量的值? SetValue
方法需要一个实例,但我希望有一种方法可以解决这个问题。
Is there anyway to set the value of a static (private) variable on an object that has not been initialized? The SetValue
method requires an instance, but I'm hoping there's a way to get around this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于静态值,您可以为实例参数传递 null。
For static values you can pass null for the instance parameter.
您可以创建一个公共静态函数并使用它来设置您的私有静态变量吗?
could you create a static function that is public and use it to set your private static variable ?