C # How to put constarint on a generic Func argument that is inside the method signature

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

I get an error, Test does not define a parameter of type TController. How to set a limit on TController?

+4
source share
2 answers

If you do not define it inside SomeClass<TController> (in this case you need to put a restriction next to the class SomeClass<TController> ), you need to make TController general argument to your function, that is:

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

You need to add TController as a general parameter

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

Source: https://habr.com/ru/post/1396731/


All Articles