mercredi 26 juillet 2017

Getting model type from expression

I'm trying to use reflection to get the model type. So far I was able to get the type of property. But when I tried to use expression to get model type, I'm getting null reference for that property.

//How I'm getting property name, I'm passing model with expression
MemberExpression expBody = expression.Body as MemberExpression;
model.GetType().GetProperty(expBody.Member.Name.ToString()));

Is it possible to do something like this?

MemberExpression expBody = expression.Body as MemberExpression;
    expBody.Type.GetProperty(expBody.Member.Name.ToString()));

I tried this, but not working.





Aucun commentaire:

Enregistrer un commentaire