我有一个基本请求类型..
类 RequestBase
{
public string inputId;
public string derivedid;
}
和继承的类型..
class RequestA : RequestBase
{
public string name;
}
和
class RequestB : RequestBase
{
public string color;
}
我有一个 webapi 服务,有些动作采用 RequestA 的输入参数,有些采用 RequestB
[HttpPost]
[MyFilter]
[ActionName("Process1")]
public HttpResponseMessage Process1(RequestA request)
{
//do something with request.derivedId
}
[HttpPost]
[MyFilter]
[ActionName("Process2")]
public HttpResponseMessage Process2(RequestB request)
{
//do something with request.derivedId
}
我有一个 actionfilter 从请求中获取 inputId 并生成一个derivedId
public override void OnActionExecuting(HttpActionContext actionContext)
{
RequestBase request = (RequestBase)actionContext.ActionArguments["request"];
string inputId = request.inputId;
string derivedId = inputId + "123";
// ?? somehow inject derivedId back into the actionContext so that my controller methods can access?
}
正如我上面的评论所述,我想填充 derivedId 字段并让我的控制器方法可以访问它。
提前致谢