1

Can someone please explain, why does the GetProperty method in System.Type returns null for properties that are declared as 'internal' but works for 'public'.

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

I understand differences between internal or public modifiers.

s2211
  • 33
  • 1
  • 9
  • See [this question](http://stackoverflow.com/questions/7575577/how-do-i-iterate-through-internal-properties-in-c-sharp) – Yacoub Massad Oct 22 '15 at 00:21

1 Answers1

4

GetProperty Method returns only public properties by default. You should include following flags

BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static 

to get internal type

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

Davlet D
  • 2,088
  • 1
  • 14
  • 14