The .NET Framework contains extensibility mechanisms that lets you create your own custom attributes. In this post we will see how to implement a Custom Attribute and use it in our applications. To start with let’s create a Console application with the name ‘CustomAttributeExample’ as shown below –
Attributes – Allows you to add extra descriptive information into Metadata. You can retrieve this information at runtime.
Now let’s add a class with the name ‘DisqualifyCustomersAttribute’ in our project and write code as shown below –
Now let’s add a ‘Customers’ class which will use the above attribute to check whether the customer is disqualified or not –
Now let’s write code to add customer information who is disqualified and try to access the information from our custom attribute, as below –
The output will be shown as below –