Skip to content
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

dynamic/ExpandoObject string member can't be passed to a function that accepts a string #295

Open
AndrewKoransky opened this issue Sep 14, 2023 · 1 comment
Labels

Comments

@AndrewKoransky
Copy link

If you add a variable to the interpreter that is a dynamic/ExpandoObject with a string member, then attempt to use that string member in a function, you get an exception:
DynamicExpresso.Exceptions.ParseException : Argument list incompatible with delegate expression (at index 0).

Here is a test that demonstrates the behavior.

var evaluator = new Interpreter();

// create path helper functions in expressions...
Func<string, string, string> pathCombine = (x, y) => System.IO.Path.Combine(x, y);
evaluator.SetFunction("PathCombine", pathCombine);

// add a GlobalSettings dynamic object...
dynamic globalSettings = new ExpandoObject();
globalSettings.MyTestPath = "C:\\delme\\";
evaluator.SetVariable("GlobalSettings", globalSettings);

// Here is a workaround that succeeds - you have to cast GlobalSettings.MyTestPath to string:
string works = (string)evaluator.Eval("PathCombine((string)GlobalSettings.MyTestPath,\"test.txt\")");
Assert.That(works, Is.EqualTo("C:\\delme\\test.txt"));

// I think this should work, but doesn't:
string doesntWork = (string)evaluator.Eval("PathCombine(GlobalSettings.MyTestPath,\"test.txt\")");
Assert.That(doesntWork, Is.EqualTo("C:\\delme\\test.txt"));

Because PathCombine takes a string, and GlobalSettings.MyTestPath is a string, I think this should work?

@metoule
Copy link
Contributor

metoule commented Nov 24, 2024

Since #296 has been reverted in #333, let's reopen this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants