Pregunta

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?

¿Fue útil?

Solución

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;
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top