Closed cesaryuan closed 3 years ago
Hello @cesaryuan ,
You are right, by default our library is case insensitive.
You can change this behavior using the following options:
// default is BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy | BindingFlags.IgnoreCase
context.BindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy;
I must admit this is not obvious for people who don't have the source code to disable this case sensitivity, so I will ask my developer to add a new option named IsCaseSensitive
to make it more obvious.
Best Regards,
Jon
Hello @cesaryuan ,
The v4.0.31 has been released.
We added a new option named IsCaseSensitive
which will automatically adjust the BindingFlags
.
For backward compatibility reason, we must keep the IsCaseSensitive = false
by default. But you can now easily modify it.
Let me know if it works as expected.
Best Regards,
Jon
@JonathanMagnan Thanks! This is already very convenient.
I have case sensitivity set to false but I get errors when I refer to properties with different case, i.e. Foo.Bar and Foo.bar.
''System.Dynamic.ExpandoObject' does not contain a definition for 'bar''.
Is there a separate setting or way to work through this to achieve case insensitivity?
To clarify, I am passing in a object parameters to Eval(), and it is properties of these parameters that I am hoping to match without case sensitivity.
Hello @stonstad ,
Could you confirm that you are doing something similar to this:
var context = new EvalContext();
context.IsCaseSensitive = false;
dynamic expando = new ExpandoObject();
expando.x = 1;
expando.y = 2;
var r1 = Eval.Execute("x + Y", expand);
I will ask my developer to look at this. I believe the "IsCaseSensitive" should also apply here. However, I'm not sure if that's possible, the problem is that we need to compile it and the ExpandoObject have no existing properties on the compilation. From an expando to another, it could be lowercase or uppercase for example.
Hey @JonathanMagnan. Your scenario above works. In my case, my x and y variables also have nested parameters. So if the variable and property is X.FOO... x.FOO and X.FOO works, but x.foo does not.
Hello @stonstad ,
We investigate it but unfortunately, we will postpone it due to the difficulty of doing it on our side (A lot of change is required if we want to do it correctly).
This is indeed something that we will want to implement but we currently missing a lot of time which makes it impossible to make this request.
We will surely look at it again in around 2-3 months but for now, that will not be supported.
Best Regards,
Jon
OK, thank you for your response, Jon. This is a very important feature for us. My client is a paid user. We look forward to learning of its availability.
From the documentation here (https://eval-expression.net/options) it looks like this should work?
// using Z.Expressions; // Don't forget to include this.
var context = new EvalContext();
// Make member case insensitive (Math.pOW = Math.Pow)
context.BindingFlags = BindingFlags.IgnoreCase | context.BindingFlags
BindingFlags
are from properties and fields from typed type.
ExpandoObject the way you want to use it is a whole different thing.
Thanks, @JonathanMagnan. I'm wondering if there might be a way to convert an ExpandoObject into a true dynamic type to enable this feature. I think I could serialize the object graph, and then deserialize it back to dynamic, but that is computationally expensive...
OK, just another thought here. What if there was an EvalDictionary<string, object> which stores keys as lower case? An overload to Eval could accept this EvalDictionary in place of an Expando IDictionary.
Thank you for resolving per #99!
Awesome ;) We will close it in this case.
It seems that the EvalContext is not case sensitive. I test the code below, and it throw errors.
Errors