O'Reilly logo

C# Primer: A Practical Approach by Stanley B. Lippman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

8.7. Implementing Our Own Attribute Class

An attribute is actually an instance of a class. We can introduce our own attributes, provided that the class representing an attribute inherits either directly or indirectly from the System.Attribute class. In addition, for nonabstract classes there must be at least one public constructor, and the class must have public accessibility. Here is a simple attribute class suggested from the Microsoft documentation. It defines an Author attribute that allows the programmer to tag her code with metadata attributes such as the implementor's name, the code version, and comment:

 [AttributeUsage( AttributeTargets.ClassMembers, AllowMultiple = true )] public class AuthorAttribute: Attribute { public AuthorAttribute( ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required