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

Accessible types in ParseLambda? #553

Open
MariaCobretti opened this issue Nov 12, 2021 · 3 comments
Open

Accessible types in ParseLambda? #553

MariaCobretti opened this issue Nov 12, 2021 · 3 comments
Assignees

Comments

@MariaCobretti
Copy link

MariaCobretti commented Nov 12, 2021

Hi,

I would like to do some mapping with the linq.dynamic package.

var expression = "new System.Collections.Generic.Dictionary<string, string>() { { \"First\", \"A\" }, { \"Second\", \"B\" } }[it]";

var lambda = DynamicExpressionParser.ParseLambda<string, string>(ParsingConfig.Default, true, expression);

var compiled = lambda.Compile();
var input = "First";
var result = compiled(input);

in the parseLambda call I am getting this exception

System.Linq.Dynamic.Core.Exceptions.ParseException: 'Type 'System.Collections.Generic.Dictionary' not found'

any way to make this accessible or is there a better way to achieve this?

@alexeyshockov
Copy link

alexeyshockov commented Nov 16, 2021

You could try something like

var config = new ParsingConfig
{
    CustomTypeProvider = new CustomTypeProvider(new[] { typeof(System.Collections.Generic.Dictionary<,>) })
};

And try to use this config instead of the default one.

@StefH
Copy link
Collaborator

StefH commented Nov 18, 2021

Adding typeof(System.Collections.Generic.Dictionary<,> will probably not work, because the parser cannot understand the <> in the expression.

I'm taking a look if this can be added easily.

@MariaCobretti
Copy link
Author

yes thats right, it translates to smth like Dictionary`2 as a string which will then cause a syntax error when you call new on it

@StefH StefH self-assigned this Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants