Skip to content

Question: DateTime constructor using ticks #439

@zspitz

Description

@zspitz

The following:

public class Person {
    public DateTime DOB { get; set; }
}
var selector = $"DOB > DateTime(633979008000000000)";
var prm = Parameter(typeof(Person));
var parser = new ExpressionParser(new[] { prm }, selector, new object[] { }, ParsingConfig.Default);
var expr = parser.Parse(null);

fails with:

System.Linq.Dynamic.Core.Exceptions.ParseException: 'A value of type 'Int64' cannot be converted to type 'DateTime''

Presumably, because Dynamic LINQ interprets DateTime(...) as a conversion from the long literal value, which isn't found; before searching for the appropriate constructor.

Is this the intended behavior?

I can work around this by passing in DateTimeKind as the second argument to the constructor:

var selector = "DOB > DateTime(633979008000000000, DateTimeKind.Unspecified)";

Is there any other way to force Dynamic LINQ to recognize this as a call to the constructor?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions