Skip to content

reiugit/CustomAttributesExample

Repository files navigation

Example with custom attributes

Generating a custom attribute using 'AttributeUsage(...)'

AttributeUsage(Inherited = True, AllowMultiple = True)

internal class CustomMarkerAttribute(string Tag) : Attribute
{
  public string Tag { get; } = Tag;
}

Setting this attribute on a sample base class

[CustomMarker("Base Tag")]
class BaseClass { }

Setting this attribute on a sample sub class

[CustomMarker("Sub Tag")]
class SubClass { }

Reading the attributes of the sub class with 'Attribute.GetCustomAttributes(...)'
returns both the attribute set on the sub class and the attribute set on the base class.

Sub Tag
Base Tag

Releases

No releases published

Packages

No packages published

Languages