本文介绍了查找与反思的私人领域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
鉴于这一类
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);
这篇关于查找与反思的私人领域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!