dimanche 13 septembre 2015

How to evaluate a simple C# string

I have been reading up Expression trees, and I think this is a good example to use them, still I can't seem to grasp how this would be done.

I have a set of strings that I want evaluated, they are all of the type:

exp == exp , or exp != exp , or exp (<,>,>=,<=) exp if exp is Numerical Type.

The exp do not need to check if they are valid I am fine with them blowing up if they are not.

My issue is, how to I parse to get the actual obj.

I want to pass a string like these below

Owner.Property.Field == 3;

or

Owner.Field == 3;

or 

Owner.Method(1) == true

And get if the evaluation is true or not. MY issue is how do I travel down the "path" on the left and get the value?

I implemented a version with Reflection, that somehow does the work - except for when, but I want this to be as performant as possible, and if possible give me a small explanation of how it works , so I can learn.





Aucun commentaire:

Enregistrer un commentaire