/// <summary> /// Get any modifiers from the specified <see cref="PropertyInfo"/>. /// </summary> public static Modifiers GetPropertyModifiers(PropertyInfo propertyInfo) { Modifiers modifiers = 0; // A property doesn't actually have modifiers - get them from the getter/setter methods MethodInfo getter = propertyInfo.GetGetMethod(true); MethodInfo setter = propertyInfo.GetSetMethod(true); if (getter != null) { modifiers = MethodRef.GetMethodModifiers(getter); if (setter != null) { // Combine the two sets of modifiers, removing any extraneous access modifiers modifiers |= MethodRef.GetMethodModifiers(setter); if (modifiers.HasFlag(Modifiers.Public)) { modifiers &= ~(Modifiers.Protected | Modifiers.Internal | Modifiers.Private); } else if (modifiers.HasFlag(Modifiers.Protected) || modifiers.HasFlag(Modifiers.Internal)) { modifiers &= ~Modifiers.Private; } } } else if (setter != null) { modifiers = MethodRef.GetMethodModifiers(setter); } return(modifiers); }
/// <summary> /// Get any modifiers from the specified <see cref="EventInfo"/>. /// </summary> public static Modifiers GetEventModifiers(EventInfo eventInfo) { Modifiers modifiers = 0; // An event doesn't actually have modifiers - get them from the adder/remover methods MethodInfo adder = eventInfo.GetAddMethod(true); MethodInfo remover = eventInfo.GetRemoveMethod(true); if (adder != null) { modifiers = MethodRef.GetMethodModifiers(adder); if (remover != null) { // Combine the two sets of modifiers, removing any extraneous access modifiers modifiers |= MethodRef.GetMethodModifiers(remover); if (modifiers.HasFlag(Modifiers.Public)) { modifiers &= ~(Modifiers.Protected | Modifiers.Internal | Modifiers.Private); } else if (modifiers.HasFlag(Modifiers.Protected) || modifiers.HasFlag(Modifiers.Internal)) { modifiers &= ~Modifiers.Private; } } } else if (remover != null) { modifiers = MethodRef.GetMethodModifiers(remover); } return(modifiers); }