定制特性类可定义构造器来获取参数。在应用特性类的实例时必须指定这些参数。
也可以在类中定义非静态公共字段、属性。
应用特性举例:
internal enum Color { Red }
[AttributeUsage(AttributeTargets.All)]
internal sealed class SomeAttribute : Attribute
{
public SomeAttribute(string name, object o, Type[] types)
{
}
}
[Some("Jeff", Color.Red, new Type[] {typeof(Math), typeof(Console)})]
internal sealed class SomeType { }