I have a generic class like below:
public class MyClass<T, TProperty>
{
MyClass(Expression<Func<T, TProperty>> expression)
{
}
}
In my case, I want to dynamically create an instance of that class using Activator. So what I need is to create an expression for the constructor. What I have are the types (System.Type) and an object (System.Object) and I want something like below:
Expression<Func<T, TProperty>> exp = x => someValue;
"someValue" is declared as object but it's real type is definitely TProperty. It's resolved by reflection so the type here is object.
The problem is that the type T and TProperty will be generic, I don't know the types until run-time so I can't cast "someValue" to TProperty. What we have are typeof(T), typeof(TProperty) and an object -,-