1

I have a set of properties, some of them have private setter and some of them have internal setter. Is there any way that at runtime I can check whether setter of a property is internal or not?

Adi Lester
  • 24,731
  • 12
  • 95
  • 110
BigBoss
  • 6,904
  • 2
  • 23
  • 38

1 Answers1

5

You can get this info using reflection:

var myType = obj.GetType();
var setMethod = myType.GetProperty(propertyName, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
                      .GetSetMethod(true);
bool isInternalSetter = setMethod != null && setMethod.IsAssembly;
Adi Lester
  • 24,731
  • 12
  • 95
  • 110