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

Consider adding an additional cast for leaf properties #108

Closed
zspitz opened this issue Mar 11, 2020 · 0 comments
Closed

Consider adding an additional cast for leaf properties #108

zspitz opened this issue Mar 11, 2020 · 0 comments

Comments

@zspitz
Copy link
Owner

zspitz commented Mar 11, 2020

Given the following code:

Expression expr = (Expression<Func<bool>>)(() => true);

the Copy watch expression context menu command produces the following (using expr as the root expression):

expr

This makes sense if the purpose is just to paste into the Watch window. But what if the user wants to write further properties in the Watch window, for example, expr.Body. Because the code expression expr is typed as Expression and not as LambdaExpression, a further cast will be required:

((LambdaExpression)expr).Body

The same is true for further property usages. For example. getting properties on the results of ((LambdaExpression)expr).Body. We'd need a further cast.

One issue -- without knowing which property is being used, we'd have to cast to the actual type of the object. Some types -- specifically Expression<T> -- get names with the generic parameter, and full assembly::

Expression<Func<bool>> expr = () => true;
Console.WriteLine(expr.GetType().FullName);
// System.Linq.Expressions.Expression0`1[[System.Func`1[[System.Boolean, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]

If this issue only comes up in Expression<T>, we could use LambdaExpression, which is higher up in the type tree.

In any case, we have to travel up the inheritance tree, looking for the first public type.

@zspitz zspitz closed this as completed in dd658fa Apr 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant