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

Allow as and is to use instances of System.Type #459

Closed
zspitz opened this issue Nov 16, 2020 · 3 comments
Closed

Allow as and is to use instances of System.Type #459

zspitz opened this issue Nov 16, 2020 · 3 comments
Labels

Comments

@zspitz
Copy link

zspitz commented Nov 16, 2020

The following:

class Foo { }
class Bar : Foo { }

var prm = Parameter(typeof(Foo));
var selector = $"as(@0)";
var parser = new ExpressionParser(new[] { prm }, selector, new object[] { typeof(Bar) }, ParsingConfig.Default);
var expr = parser.Parse(null);

fails with:

System.Linq.Dynamic.Core.Exceptions.ParseException: 'The 'as' function requires one argument which is not null.'

The same happens with is:

var selector = $"is(@0)";

It might be helpful to clarify the error by explaining that the one argument must be the FullName of the type.

But I suggest it be possible to accept a System.Type, and FullName should be read from the type.

@StefH
Copy link
Collaborator

StefH commented Dec 2, 2020

I've updated the code to support also Type for As, Is, OfType and Cast.

However, it needs to be a constant value (note that your example works fine with the code fix)

@zspitz
Copy link
Author

zspitz commented Dec 2, 2020

However, it needs to be a constant value

In other words, if I have a property or method which returns a Type, it's not going to work?

@StefH
Copy link
Collaborator

StefH commented Dec 2, 2020

Correct, that will not yet work.

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