首页 > 编程语言 >C# 查找特性标识的所有类并获取属性值

C# 查找特性标识的所有类并获取属性值

时间:2023-04-25 23:45:03浏览次数:33  
标签:string C# System Method 标识 查找 using public Description

写个方法去获取被特性(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; }
    }
}

 

标签:string,C#,System,Method,标识,查找,using,public,Description
From: https://www.cnblogs.com/OneSeting/p/17354374.html

相关文章

  • [LeetCode] 2418. Sort the People
    Youaregivenanarrayofstrings names,andanarray heights thatconsistsof distinct positiveintegers.Botharraysareoflength n.Foreachindex i, names[i] and heights[i] denotethenameandheightofthe ith person.Return names sorted......
  • 用COPULA模型进行蒙特卡洛(MONTE CARLO)模拟和拟合股票收益数据分析|附代码数据
    全文下载链接:http://tecdat.cn/?p=24535最近我们被客户要求撰写关于COPULA模型蒙特卡洛的研究报告,包括一些图形和统计输出。最近,copula在仿真模型中变得流行起来。Copulas是描述变量之间依赖关系的函数,并提供了一种创建分布以对相关多元数据建模的方法使用copula,数据分析师......
  • ARMA-EGARCH模型、集成预测算法对SPX实际波动率进行预测|附代码数据
    全文下载链接:http://tecdat.cn/?p=12174最近我们被客户要求撰写关于ARMA-EGARCH的研究报告,包括一些图形和统计输出。本文比较了几个时间序列模型,以预测SP500指数的每日实际波动率。基准是SPX日收益序列的ARMA-EGARCH模型。将其与GARCH模型进行比较 。最后,提出了集合预测算法......
  • SQL Server实现group_concat功能的详细实例
    目录一、实现二、原理分析2.1、FOR XML PATH的作用2.2、STUFF函数2.2.1、STUFF函数在本SQL的作用2.2.2、STUFF函数语法2.3、sql语分分析2.3.1、一个简单的group by2.3.2、在select语句后面加上子查询2.3.3、去掉子查询结果集的第一个分隔符总结一、实......
  • Winform使用EFCore的CodeFirst(注入方式)
    1、新建项目使用vs创建一个winform的项目,这里就不演示了。2、拉取nuget包获取配置:Microsoft.Extensions.Configuration.Json注入:Microsoft.Extensions.DependencyInjectionmysqlEF:MySql.EntityFrameworkCore3、创建appsettings.json配置文件在项目......
  • opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization e
    原因:node版本与openssl不兼容导致的初始化失败 解决:windows执行:setNODE_OPTIONS=--openssl-legacy-providermac执行:exportNODE_OPTIONS=--openssl-legacy-provider......
  • spring mvc3.2 请求及响应过程
    doFilter-->doFilterInternal-->filterChain.doFilter-->HttpServletservice(request,response)-->doGet(req,resp)-->DispatcherServletservice(ServletRequestreq,ServletResponseres)-->FrameworkServlet.processRequest-->doDispatch(request......
  • 【LeetCode动态规划#13】买卖股票含冷冻期(状态众多,比较繁琐)、含手续费
    最佳买卖股票时机含冷冻期力扣题目链接(opensnewwindow)给定一个整数数组,其中第i个元素代表了第i天的股票价格。设计一个算法计算出最大利润。在满足以下约束条件下,你可以尽可能地完成更多的交易(多次买卖一支股票):你不能同时参与多笔交易(你必须在再次购买前出售掉之前......
  • 美国销售税合规平台TaxCloud完成2000万美元融资
    猛兽财经获悉,总部位于加州诺沃克面向电子商务企业的销售税合规平台TaxCloud近期宣布完成2000万美元融资。本轮融资由CamberPartners领投。该公司打算利用这笔资金继续为其客户提供服务,同时扩大其产品供应、营销和销售。作为投资的一部分,TaxCloud宣布任命NateGilmore为首席执行......
  • JDBC访问数据库
    下载,安装MySQL(下载地址:https://www.mysql.com/downloads/)创建数据库——createdatabase<数据库名>创建用户——mysql>grantallprivilegeson数据库名.*to新用户名@locahost identifiedby‘密码’;使用DDL创建表——createtable表名(字段名数据类型是否主键/非空)使用DML操......