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 use of as and is on arbitrary expressions, not just the parameter #457

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

Comments

@zspitz
Copy link

zspitz commented Nov 16, 2020

Currently, as is defined as taking only one argument: the type name; it can only be applied to the parameter. This:

class Foo {}
class Bar : Foo {}
class Baz {
    public Foo Foo1 {get;set;} = new Bar();
}

var selector = $"as(\"{typeof(Bar).FullName}\")";

is defined as the equivalent of:

x => x as Bar;

But there is no way to express the equivalent of the following:

Expression<Func<Baz, Bar>> expr = x => x.Foo1 as Bar;

Either of the following:

var selector = $"as(Foo1, \"{typeof(Bar).FullName}\")";
var selector = $"as(\"{typeof(Bar).FullName}\", Foo1)";

fails with:

System.Linq.Dynamic.Core.Exceptions.ParseException: 'The 'as' function requires one argument'


The same thing applies to is. Either of the following:

var selector = $"is(Foo1, \"{typeof(Bar).FullName}\")";
var selector = $"is(\"{typeof(Bar).FullName}\", Foo1)";

fails with the above error.

@zspitz zspitz changed the title Allow use of as on non-ParameterExpression Allow use of as on arbitrary expressions, not just the parameter Nov 16, 2020
@zspitz zspitz changed the title Allow use of as on arbitrary expressions, not just the parameter Allow use of as and is on arbitrary expressions, not just the parameter Nov 16, 2020
@StefH StefH self-assigned this Jan 20, 2021
@StefH
Copy link
Collaborator

StefH commented Jan 20, 2021

Hello @zspitz ,

For this moment it needs to be a constant value (Type or string).

This question is also related #459.

Closing this issue.

@zspitz
Copy link
Author

zspitz commented Feb 19, 2022

This has now been fixed with #567, see #566.

@zspitz
Copy link
Author

zspitz commented Feb 19, 2022

For this moment it needs to be a constant value (Type or string).

@StefH Note that this issue is unrelated to passing the type/string as a parameter object to the Dynamic Linq expression; this issue is about applying as/is to an arbitrary expression.

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