首页 > 解决方案 > 从具有强类型的特定控制器获取特定操作的路由列表

问题描述

我希望能够获取控制器特定操作的路由。

这是签名。

string extractRoute<T>(Action<T> action)
{
     doing something 

     return string.Empty;
 }

我想像这样使用它:

string route1 = extractRoute<SomeController>(x => x.GetAll);
string route2 = extractRoute<SomeController>(x => x.Delete);

结果将存储在一个集合中

得到这个编译错误

只有 assignment、call、increment、decrement、await 和 new 对象表达式可以用作语句

SomeController 是一个 API 控制器

GetAll 是该控制器上的一个动作。

Task<ActionResult<SomeResult>> GetAll(Request requesT) 
{
      throw new System.NotImplemented(); 
}

删除是该控制器上的一个动作。

Task<ActionResult<bool>> Delete (int id) 
{
      throw new System.NotImplemented(); 
}

标签: c#.netasp.net-corelambda.net-core

解决方案


推荐阅读