写个方法去获取被特性(Attribute)标记的类,并且获取标记的属性值
using OneLove.Core.ExtendedEnum; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace OneLove.Core.ExtendedAttribute { public class SchedulingAttribute : Attribute { private string Url; private HttpMethods Method; private string Description; public SchedulingAttribute(string url, HttpMethods method, string description = null) { Url = url; Method = method; Description = description; } public List<SchedulinEntity> GetSchedulingAttributeList() { System.Reflection.Assembly asm = System.Reflection.Assembly.GetAssembly(typeof(SchedulingAttribute)); System.Type[] types = asm.GetExportedTypes(); List<SchedulinEntity> list = new List<SchedulinEntity>(); foreach (Type type in types) { var attrs = type.GetCustomAttributes<SchedulingAttribute>(); foreach (var attr in attrs) { if (attr is SchedulingAttribute) { list.Add(new SchedulinEntity() { Description = attr.Description, Method = attr.Method, Url = attr.Url, ApiClassName = type.Name }); } } } return list; } } public class SchedulinEntity { public string Url { get; set; } public HttpMethods Method { get; set; } public string Description { get; set; } public string ApiClassName { get; set; } } }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架