mercredi 23 juin 2021

How to get a list of variable names corresponding to properties used in a LambdaExpression?

I have a LambdaExpression which has a lambda body like x => x.FirstName == "Joe" And x.LastName == "Bloggs" (it can also contain more properties and it can also contain Or operators).

How do I get a List<string> of all the property names used in that lambda? So the list would look like below based on the lambda above.

FirstName
LastName 

There are other stackoverflow pages which somehow cast their Expression to MemberExpression, however this does not work for me because it won't cast properly.An example of what I'm trying to do is like this answer below but that is returning PropertyInfo rather than a list of strings

https://stackoverflow.com/a/672212/1389239





Aucun commentaire:

Enregistrer un commentaire