public void Test<TFeature>(Func<TController, ViewResult> controllerAction)
where TController : IController
where TFeature : ISecurityFeature
{
...
}
我收到错误, Test没有定义类型参数TController 。如何在TController上设置约束?
答案 0 :(得分:5)
您还需要将TController添加为通用参数
public void Test<TFeature, TController>(Func<TController, ViewResult> controllerAction)
where TController : IController
where TFeature : ISecurityFeature
{
...
}
答案 1 :(得分:5)
除非你在SomeClass<TController>
中定义它(在这种情况下你需要在class SomeClass<TController>
旁边放置约束),你需要使TController
成为你函数的泛型参数,即:
public void Test<TFeature, TController>(Func<TController, ViewResult> controllerAction)
where TController : IController
where TFeature : ISecurityFeature
{
...
}