mvc利⽤反射获取Controller中Action和注解1、获取控制器所有Action:
Type t = typeof(StatController);//StatController是指定控制器的名称
System.Reflection.MethodInfo[] ControllerMethods = t.GetMethods();
StringBuilder methodsNameAppend = new StringBuilder();
for (int i = 0; i < ControllerMethods.Length; i++)
{
methodsNameAppend.Append(ControllerMethods[i].Name + ";");
}
mvc的controller2、获取备注: [DescriptionName("应收费录⼊内容")]定义⼀个过滤器表头
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Soarway.WYGL.API.Controllers
{
class DescriptionNameAttribute : Attribute
{
public string DescriptionName { get;set;}
public DescriptionNameAttribute(string name)
{
this.DescriptionName=name;
}
}
}
3、实例:ControllerMethods[8].GetCustomAttributesData()[1].ConstructorArguments[0].Value获取过滤器名称

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。