Creating Custom Attributes

First and foremost, attributes are classes that are subclassed from the System.Attribute class. The implication is that all the skills you have acquired can be used to generalize the Attribute class and define custom attributes.

Custom attributes allow third parties to participate in extending the .NET framework. To demonstrate creating custom attributes, I will walk you through creating the HelpAttribute introduced in the VS .NET documentation. Let's review a couple of guidelines for creating custom attributes first.

  • Add the Attribute suffix to the attribute class name.

  • Apply the AttributeUsageAttribute to the custom attribute class, indicating intended usage.

  • Use positional arguments for required information.

  • Use named ...

Get Visual Basic® .NET Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.