mercredi 10 octobre 2018

Pass Type to Expression Func Out

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]);





Aucun commentaire:

Enregistrer un commentaire