C# 自定义特性
using System; namespace ConsoleApp1 { class Program { static void Main(string[] args) { HelpAttribute helpAttribute; foreach (var item in typeof(AnyClass).GetCustomAttributes(true)) { helpAttribute = item as HelpAttribute; if (helpAttribute.Name != null) { Console.WriteLine(helpAttribute.Name); } } } } [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)] public class HelpAttribute : Attribute { private string name; public string Name { get { return this.name; } } public HelpAttribute(string _name) { this.name = _name; } } [Help("name")] public class AnyClass { } }