Csharp/CSharp Tutorial/Attribute/AttributeUsage

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

AttributeUsage

The AttributeUsage attribute specifies the types of items to which an attribute can be applied.

AttributeUsage is another name for the System.AttributeUsageAttribute class.

AttributeUsage has the following constructor:


AttributeUsage(AttributeTargets item)

Define a attribute for remark

using System;
[AttributeUsage(AttributeTargets.All)] 
public class MyAttribute : Attribute { 
  string remark;
 
  public MyAttribute(string comment) { 
    remark = comment; 
  } 
 
  public string Remark { 
    get { 
      return remark; 
    } 
  } 
}