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

UriKind is not recognized in Uri constructor #442

Closed
zspitz opened this issue Oct 28, 2020 · 5 comments
Closed

UriKind is not recognized in Uri constructor #442

zspitz opened this issue Oct 28, 2020 · 5 comments
Labels

Comments

@zspitz
Copy link

zspitz commented Oct 28, 2020

System.Uri is a predefined type.

The following:

class Person { }

var selector = "Uri(\"https://www.example.com/\", UriKind.Absolute)";
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: 'No property or field 'UriKind' exists in type 'Person''

UriKind appears to be understood as a member of Person, and not as an enum value.

This is especially puzzling, because the following selector:

var selector = "DateTime(633979008000000000, DateTimeKind.Local)";

is parsed just fine.

Could it be because there is a string literal within the first selector?

@StefH
Copy link
Collaborator

StefH commented Oct 28, 2020

Hello @zspitz.

A small remark: you always use the ExpressionParser in your examples.

However this class does not exists in this repository, it should be DynamicExpressionParser.
https://github.com/zzzprojects/System.Linq.Dynamic.Core/blob/master/src/System.Linq.Dynamic.Core/DynamicExpressionParser.cs

I think you are mistaken by another source code repository?

@StefH
Copy link
Collaborator

StefH commented Oct 29, 2020

You are correct.

However I think the DynamicExpressionParser is a more public class, and the ExpressionParser is more internal. That's why I was confused.

@StefH
Copy link
Collaborator

StefH commented Nov 1, 2020

Hello @zspitz,

As a workaround you can use the integer value from the enum:
Uri(\"https://www.example.com/\", 0)

or

Use parameter:

var selector = "Uri(\"https://www.example.com/\", @0)";
var prm = Expression.Parameter(typeof(Uri));
var parser = new ExpressionParser(new[] { prm }, selector, new object[] { UriKind.Absolute }, ParsingConfig.Default);
var expr = parser.Parse(null);

I'll investigate further on the details on this issue.

@StefH
Copy link
Collaborator

StefH commented Nov 15, 2020

Solved by #450

@StefH StefH closed this as completed Nov 15, 2020
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