s22*_*211 2 .net c# access-modifiers
有人可以解释一下,为什么 System.Type 中的 GetProperty 方法对于声明为“内部”但适用于“公共”的属性返回 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
Run Code Online (Sandbox Code Playgroud)
我了解内部或公共修饰符之间的差异。
GetProperty 方法默认仅返回公共属性。您应该包含以下标志
BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static
Run Code Online (Sandbox Code Playgroud)
获取内部类型
MSDN: https://msdn.microsoft.com/en-us/library/zy0d4103 (v=vs.110).aspx