自定义特性
/* 自定义特性 */ using System; namespace Frank { public class Test { [FileName("Name")] public string Name {get;set;} //程序入口 public static void Main(string[] args) { Test t = new Test(); t.Name="1"; } } //AllowMultiple 表示一个地方是否可以重复使用属性 //Inherited 表示是否可以应用到派生类 //AttributeTargets 是一个枚举,声明可以在哪些地方使用改特性。 [AttributeUsage(AttributeTargets.Property | AttributeTargets.Class,AllowMultiple=false,Inherited=false)] public class FileNameAttribute : Attribute { private string name; public FileNameAttribute(string name) { this.name = name; Console.WriteLine(name); } } }