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

Static helper class with name as property doesn't work after updating from v.1.0.8.18 to 1.3.8 #772

Closed
OlegNadymov opened this issue Feb 6, 2024 · 6 comments
Assignees
Labels

Comments

@OlegNadymov
Copy link
Contributor

OlegNadymov commented Feb 6, 2024

In continuation of #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?

@StefH StefH self-assigned this Feb 7, 2024
@StefH
Copy link
Collaborator

StefH commented Feb 7, 2024

@OlegNadymov
I assume that you did add that UserInfo to the types in that TestCustomTypeProvider ?

@OlegNadymov
Copy link
Contributor Author

Yes, I did:
image

@StefH
Copy link
Collaborator

StefH commented Feb 7, 2024

#774

@OlegNadymov
Copy link
Contributor Author

The problem in my case is the class User has property named UserInfo exactly as static class UserInfo (like in my demo above).

@StefH
Copy link
Collaborator

StefH commented Feb 8, 2024

#773

@StefH
Copy link
Collaborator

StefH commented Feb 29, 2024

PR merged, a new NuGet will be released in some time

@StefH StefH closed this as completed Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants