delegate IEnumerable<T> GetFromSQLDelegate<T>(...);
public GetFromSQLDelegate myFunctionToCall;
The above does not compile because myFunctionToCall does not specify a type. I’m trying to “store” a generic delegate such that I can invoke it later as a regular generic function:
// ... somewhere in another code base ...
return MyObject.myFunctionToCall<string>(...);
C# complains because I’m not specifying a concrete type on the delegate storage property. Is there a (good) way to “store” a delegate capable of invoking a generic function without implementing various concrete type delegate scenarios?
You can store the value as
System.Delegate, make itprivate, and define a functionGetDelegate<T>that casts your stored delegate to the appropriate type:You can then call it like this:
There is a little bit of ugliness going on around the
()(...)syntax, but it should probably do the trick.