Find a private field with Reflection?

前端 未结 10 1189
自闭症患者
自闭症患者 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:49

    typeof(MyType).GetField("fieldName", BindingFlags.NonPublic | BindingFlags.Instance)
    

提交回复
热议问题