鉴于这一类
class Foo
{
// Want to find _bar with reflection
[SomeAttribute]
private string _bar;
public string BigBar
{
get { return this._bar; }
}
}
我想找到私人物品_bar,我将与属性标记。那可能吗?
I want to find the private item _bar that I will mark with a attribute. 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?
使用 BindingFlags.NonPublic可
和 BindingFlags.Instance
标志
FieldInfo[] fields = myType.GetFields(
BindingFlags.NonPublic |
BindingFlags.Instance);