-
Notifications
You must be signed in to change notification settings - Fork 85
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
Support of DynamicObject or IDictionary<string, object> as context object #44
Comments
Hello @tomasceleda , There is a lot of way to do it. For example: https://dotnetfiddle.net/zclC3l // ExpandoObject
{
dynamic dynamicObj = new ExpandoObject();
dynamicObj.X = 1;
dynamicObj.Y = 2;
Console.WriteLine(Eval.Execute<int>("X + Y", dynamicObj));
}
// VariableFactory
{
var context = new EvalContext();
context.VariableFactory = arg => {
if(arg.Name == "X")
{
arg.Value = 1;
arg.IsHandled = true;
}
else if (arg.Name == "Y")
{
arg.Value = 2;
arg.IsHandled = true;
}
};
Console.WriteLine(context.Execute<int>("X + Y"));
} We will look about your both scenario to see why it throw an error. Best Regards, Jonathan |
Interesting ... I hit this ... Apart from the typo in my query code (referring to properties that don't exist I found that the problem was much the same. I'm using Eval like this ...
... by doing the json bit at the end I can "not worry about selections having to create new t { }" instances during the querying process for the simple cost of a bit of cpu time (hense the reason that's there). Query in this case is a custom thing I built to wrap around Eval, what it is is a Json based structure I can build out in my web based front end to define queries on objects. In this case (as seen from the stackoverflow post I have a dynamic object that I built from getting data from multiple places (some items, some company data, ect) that I collected together in to my Eval context object. Having done that I noticed using Eval in this manner must be doing something like this in the background when we use "EvalContext.IncludeMemberFromAllParameters = true" ...
Whereas if it did ...
Then I believe this would work. For the purpose of Eval here I think it might be "cleaner" in terms of user use case to always treat ExpandoObjects as dynamic although i have to admit I haven't really spent enough time to know for sure if that would cause unintended side effects. |
Hello @tomasceleda , This issue will be closed since we answered it. We will continue the @TehWardy request on the newly thread he created Best Regards, Jonathan |
If I run
where ServiceExample2 is inherits from Dictionary<string, object> it works as expected. When it implements IDictionary<string, object> or inherits DynamicObject and implements the properties dynamically, it throws NullReferenceException.
Is there some other way how to run on object with has not the properties known at compile time?
Thanks
The text was updated successfully, but these errors were encountered: