Skip to content

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

Closed
@david-garcia-garcia

Description

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)

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions