I need to be able to get the type from the currentStep variable and use that type for the newExpression assignment. What this code is doing is changing the Expression out type. Is there a way where I can dynamically set the newExpression func out type based on the currentStep type?
PropertyInfo currentStep = wizardTransaction.GetCurrentStepPropertyInfo();
string currentStepName = wizardTransaction.GetCurrentStepPropertyInfo().PropertyType.Name;
var body = Expression.Property(expression.Body, currentStepName);
var newExpression = Expression.Lambda<Func<TModel, **currentStep.GetType()**>>(body, expression.Parameters[0]);
var model = ModelMetadata.FromLambdaExpression(newExpression, helper.ViewData).Model;
The method which the above code is in is a static class so the answer thats the solution that this is marked as a duplicate for does not apply as the this keyword used in the accepted answer cant not be used in a static class.