I know it's possible to set the inheritance behavior of an attribute you've defined:
[AttributeUsage(Inherited = True)]
SomeInheritedAttribute : Attribute
{
}
But can I alter that behavior for a single use of the attribute? My current use case is the [JsonObject(MemberSerialization.OptIn)]
attribute. It's inherited by default, and I'd like to change that for individual uses.
One thought was to define my own attribute inheriting from JsonObject
:
[AttributeUsage(Inherited = False)]
NonInheritedJsonObject : JsonObject
{
}
But as Mike pointed out, that class is sealed.
Is there a way to mark an attribute instance (terminology?) as non-inherited?