使用 Reflection 查找私有字段? - Find a private field with Reflection?

10/14 02:12
阅读数 0

问题:

Given this class鉴于这个类

class Foo
{
    // Want to find _bar with reflection
    [SomeAttribute]
    private string _bar;

    public string BigBar
    {
        get { return this._bar; }
    }
}

I want to find the private item _bar that I will mark with a attribute.我想找到我将用属性标记的私有项 _bar。 Is that possible?那可能吗?

I have done this with properties where I have looked for an attribute, but never a private member field.我已经使用我寻找属性的属性完成了此操作,但从未使用过私有成员字段。

What are the binding flags that I need to set to get the private fields?我需要设置哪些绑定标志才能获取私有字段?


解决方案:

参考一: https://en.stackoom.com/question/Oww
参考二: https://stackoom.com/question/Oww
展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部