Find a private field with Reflection?

前端 未结 10 1395
自闭症患者
自闭症患者 2020-11-22 16:17

Given this class

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

    public string BigBar
    {
        ge         


        
10条回答
  •  天涯浪人
    2020-11-22 16:59

    Yes, however you will need to set your Binding flags to search for private fields (if your looking for the member outside of the class instance).

    The binding flag you will need is: System.Reflection.BindingFlags.NonPublic

提交回复
热议问题