C# Attributes

Overview
Allow programmers to annotate various entities to be retrieved at runtime

Reference
MSDN

Attribute Classes
Inherites from abstract System.Attribute class
Use of suffix Attribute is preferred
Can have
positional parameters (defined in public constructors)
named parameters (public non-static read-write properties)
Example:

using System;
[AttributeUsage(AttributeTargets.Class)]
public class HelpAttribute: Attribute
{
   // Positional parameter
   public HelpAttribute(string url) {
      ...
   }
   // Named parameter
   public string Topic {
      get {...}
      set {...}
   }
   public string Url {
      get {...}
   }
This entry was posted in c#. Bookmark the permalink.