-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failed DateTime.Now #22
Comments
You cannot access static methods / properties directly in the expression, this is by design (to guarantee that expressions may use only explicitly defined context). It is possible to expose DateTime.Now in the following way:
another approach: usage of special 'API' objects in the context
|
Thanks. If I were to something like this, would it work?
If so, it would be possible to give more static class contexts. I understand that "DateTime.Now()" is needed instead of "DateTime.Now", but is it possible to do this some other way? I ask this because I tried DynamicExpresso and Flee, but both of them were not able to do what I wanted. I assigned a=1, b=2, c=a+b and then d = c+a. DynamicExpresso and Flee evaluated d to a+b1 instead of 4. But lambdaparser did it correctly so I tried more examples but it failed when I tested the DateTime. |
this will not work because DateTime refers to System.Type. You need to pass an object that has properties/methods. You may use an approach with DateTimeApi to enable a syntax similar to C# (like "DateTime.Now") and add to DateTimeApi any properties/methods you want to expose for expressions. |
I used the simple code but it resulted in a null reference exception. Is this supported?
var varContext = new Dictionary<string, object>();
var lambdaParser = new NReco.Linq.LambdaParser();
Console.WriteLine(lambdaParser.Eval("System.DateTime.Now", varContext));
Console.Read();
The text was updated successfully, but these errors were encountered: