mercredi 26 mai 2021

Parsing a string formula by injecting object values (i.e. using reflection) in C#

I need to parse a formula in string format which can contain objects and properties.

Example:

"Person1.Age > 20" or "Person1.Age > RentalCar5.MinimumAge"

Where Person1 would be an object of type Person, and RentalCar5 an object of type RentalCar.

I have the objects, so can check the formula contains "Person1" and know it to be a Person object matching that specific Name property, so I need to then determine the Age property value, then replace the whole "Person1.Age" section with the age, such as 21.

Once this is done it would be easy enough to resolve the formula as "21 >20"

Any thoughts or ideas?





Aucun commentaire:

Enregistrer un commentaire