GetProperty 方法 returns null C# .Net

GetProperty Method returns null C# .Net

有人可以解释一下,为什么 System.Type returns 中的 GetProperty 方法对于声明为 'internal' 但适用于 'public' 的属性为 null。

internal class Test{      
  public string ALocal { get; set; }
  internal string SLocal { get; set; }}

var test = new Test();
var testType = test.GetType();

var aProp = testType.GetProperty("ALocal"); => returns string Type
var sProp = testType.GetProperty("SLocal"); => returns null

我了解内部修饰符或 public 修饰符之间的区别。

GetProperty 方法 returns 默认只有 public 个属性。 您应该包括以下标志

BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static 

获取内部类型

MSDN: https://msdn.microsoft.com/en-us/library/zy0d4103(v=vs.110).aspx