I have an interesting question for you all.
public Func<T, int> GetLambdaFor<T>()
{
// ....
}
public void SetLambdaForAnyType(Func<?, int> lambda)
{
// ....
}
In the code sample above I would like to find out if it is at all possible to specify a substitutable Generic
lambda expression
in C#
using the SET method while retrieving a specifically typed Generic
lambda expression
using the GET method.
So let me give an example (ofcourse it features broken C#
, I would like to find out if it is possible and if so, how to do it):
MyClass.SetLambdaForAnyType<?>((a) => new SomeValueGenerator<?>(a).GetValue());
int generateValue = MyClass.GetLambdaFor<string>()("blah");
generateValue = MyClass.GetLambdaFor<DateTime>()(DateTime.Now);
// etc...
I hope it makes more sense now. Any ideas? If it is not possible, any alternative possibilities?