Static helper class with name as property doesn't work after updating from v.1.0.8.18 to 1.3.8
In continuation of https://github.com/zzzprojects/System.Linq.Dynamic.Core/issues/759
1. Description
Simplified demo:
public static class UserInfo
{
public static Guid Key => Guid.NewGuid();
}
public class User
{
public Guid Id { get; set; }
public User UserInfo { get; set; }
}
I try to parse the expression this way:
var config = new ParsingConfig
{
CustomTypeProvider = new TestCustomTypeProvider()
};
var exp = "Id == UserInfo.Key";
var lambda = System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda(config, typeof(User), null, exp);
But I got exception:
System.Linq.Dynamic.Core.Exceptions.ParseException : No property or field 'Key' exists in type 'User'
If I put the full type name:
var exp = "Id == System.Linq.Dynamic.Core.Tests.UserInfo.Key";
I have another exception:
System.Linq.Dynamic.Core.Exceptions.ParseException : Enum value 'Key' is not defined in enum type 'System.Linq.Dynamic.Core.Tests.UserInfo'
2. Exception
The first stack trace:
System.Linq.Dynamic.Core.Exceptions.ParseException : No property or field 'Key' exists in type 'User'
Stack Trace:
ExpressionParser.ParseMemberAccess(Type type, Expression expression) line 1891
ExpressionParser.ParsePrimary() line 819
ExpressionParser.ParseUnary() line 806
ExpressionParser.ParseArithmetic() line 751
ExpressionParser.ParseAdditive() line 718
ExpressionParser.ParseShiftOperator() line 694
ExpressionParser.ParseComparisonOperator() line 492
ExpressionParser.ParseLogicalAndOrOperator() line 414
ExpressionParser.ParseIn() line 325
ExpressionParser.ParseAndOperator() line 308
ExpressionParser.ParseOrOperator() line 290
ExpressionParser.ParseLambdaOperator() line 270
ExpressionParser.ParseNullCoalescingOperator() line 257
ExpressionParser.ParseConditionalOperator() line 241
ExpressionParser.Parse(Type resultType, Boolean createParameterCtor) line 156
DynamicExpressionParser.ParseLambda(Type delegateType, ParsingConfig parsingConfig, Boolean createParameterCtor, ParameterExpression[] parameters, Type resultType, String expression, Object[] values) line 121
DynamicExpressionParser.ParseLambda(ParsingConfig parsingConfig, Boolean createParameterCtor, ParameterExpression[] parameters, Type resultType, String expression, Object[] values) line 98
DynamicExpressionParser.ParseLambda(ParsingConfig parsingConfig, Boolean createParameterCtor, Type itType, Type resultType, String expression, Object[] values) line 357
DynamicExpressionParser.ParseLambda(ParsingConfig parsingConfig, Type itType, Type resultType, String expression, Object[] values) line 319
DynamicExpressionParserTests.DynamicExpressionParser_ParseLambda_Operator_Less_Greater_With_Guids() line 1465
3. Fiddle or Project
Again, I have done changes in DynamicExpressionParserTests only locally.
4. Any further technical details
The first version of expression (non-full type name) was working v.1.0.8.18. But it is not working on the release version 1.3.8.
Is it possible to fix it?
@OlegNadymov
I assume that you did add that UserInfo to the types in that TestCustomTypeProvider ?
Yes, I did:
https://github.com/zzzprojects/System.Linq.Dynamic.Core/pull/774
The problem in my case is the class User has property named UserInfo exactly as static class UserInfo (like in my demo above).
https://github.com/zzzprojects/System.Linq.Dynamic.Core/issues/773
PR merged, a new NuGet will be released in some time