public void Test<TFeature>(Func<TController, ViewResult> controllerAction)
            where TController : IController
            where TFeature : ISecurityFeature
        {
            ...
        }

我得到一个错误,test没有定义类型参数tcontroller。我怎样才能约束tcontroller?

最佳答案

除非在SomeClass<TController>中定义它(在这种情况下,需要在class SomeClass<TController>旁边放置约束),否则需要将TController作为函数的一般参数,即:

public void Test<TFeature, TController>(Func<TController, ViewResult> controllerAction)
            where TController : IController
            where TFeature : ISecurityFeature
        {
            ...
        }

10-04 17:57