Skip to content

OfType(string) fails with "'.' or '(' or string literal expected" when AllowNewToEvaluateAnyType is true on version 1.2.24 and above #692

@jbhelm

Description

@jbhelm

Calling OfType() when AllowNewToEvaluateAnyType is true fails on version 1.2.24 and above; it works on 1.2.23.

Here's a repro:

using System.Linq.Dynamic.Core;

namespace DynamicLinqExample {

    internal class Base { }

    internal class DerivedA : Base { }

    internal class DerivedB : Base { }

    internal class Parent {
        public IEnumerable<Base> Children { get; set; }
    }


    internal class Program {
        private static readonly ParsingConfig DefaultParsingConfig = new() {
            AllowNewToEvaluateAnyType = true,   // <-- works if this is false
        };

        static void Main(string[] args) {
            var data = new Parent[] {
                new() {
                    Children = new Base[] {
                        new DerivedA(),
                        new DerivedB(),
                    }
                }
            };

            var query = data.AsQueryable()
                .Select(DefaultParsingConfig, "Children.OfType(\"DynamicLinqExample.DerivedA\")");
            var result = query.ToDynamicArray();
        }
    }
}

This results in:

System.Linq.Dynamic.Core.Exceptions.ParseException
  HResult=0x80131500
  Message='.' or '(' or string literal expected
  Source=System.Linq.Dynamic.Core
  StackTrace:
   at System.Linq.Dynamic.Core.Tokenizer.TextParser.ValidateToken(TokenId tokenId, String errorMessage)

Thanks!

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions