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

Issue: new() expression cannot handle complex types #206

Closed
david-garcia-garcia opened this issue Oct 16, 2018 · 4 comments
Closed

Issue: new() expression cannot handle complex types #206

david-garcia-garcia opened this issue Oct 16, 2018 · 4 comments

Comments

@david-garcia-garcia
Copy link
Contributor

Currently, the new() expression can be used to instantiate know types, such as:

query = query.select("new MyNamespace.MyClass(value1 as prop1, value2 as prop2)");

ExpressionParser.cs is not able to properly handle complex types, such as generics or classes nested inside other classes, i.e.

query = query.select("new MyNamespace.MyClass+MySubClass(value1 as prop1, value2 as prop2)");

The parser is properly extracting the full namespace and class name, it just fails to properly detect the type in it's FindType() method. I really don't understand why the implementation of such a method is so convoluted, but following the current philosophy of the method, this is the patch that will allow new() to parse nested class names:

image

To properly support generics though some extra work needs to be done, as it will only consider dot and plus as valid tokens in a class name:

while (_textParser.CurrentToken.Id == TokenId.Dot || _textParser.CurrentToken.Id == TokenId.Plus)

@david-garcia-garcia
Copy link
Contributor Author

Will be proposing a PR when I find some time, just posting here for the record.

@StefH StefH changed the title new() expression cannot handle complex types Issue: new() expression cannot handle complex types Oct 16, 2018
@StefH
Copy link
Collaborator

StefH commented Oct 16, 2018

Thanks for the PR.

Can you also add a new unit-test to test this specific issue?

@StefH
Copy link
Collaborator

StefH commented Oct 16, 2018

Tests fail; related to the test DTO classes, these should be normal classes, not nested in a test class.

@StefH
Copy link
Collaborator

StefH commented Oct 19, 2018

NuGet 1.0.9 is added.

@StefH StefH closed this as completed Oct 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants