System.Linq.Dynamic.Core
System.Linq.Dynamic.Core copied to clipboard
Accessible types in ParseLambda?
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?
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.
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.
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