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

Equivalent for Expression Trees #50

Closed
rikimaru0345 opened this issue May 30, 2019 · 7 comments
Closed

Equivalent for Expression Trees #50

rikimaru0345 opened this issue May 30, 2019 · 7 comments

Comments

@rikimaru0345
Copy link

Hey @KirillOsenkov, first of all RoslynQuoter is really useful, thank you for making it!

However I'm currently looking for a way to do the same for expression trees.
Basically taking c# source code and turning it into Expression.* calls.
Like an "Expression Tree Quoter" 😄

Google wasn't of any help and since you made this awesome tool, I figured I should just ask you if you're aware of any way that could be done; or maybe a project that already does this. 😄

@svick
Copy link
Contributor

svick commented May 30, 2019

Have you tried decompiling the result of what the C# compiler does?

For example here is the result of decompiling a simple Expression, which shows you how to build it yourself using calls to methods on Expression.

@rikimaru0345
Copy link
Author

Yes, but this isn't so much about getting it done at all (just to look at it), but rather about having an automated way (a library!) to do it.
Like a string ConvertCSharpToExpressionCalls(string cSharpCode);, hope that makes sense.

@svick
Copy link
Contributor

svick commented May 30, 2019

Could you explain why you want that?

Generally, the output of a quoter is useful for a human, because they can then use it to write some other code.

But if you want a library, that usually means you want to process the output by a program. But what kind of program prefers e.g. Expression.Lambda<Func<int>>(Expression.Constant(0, typeof(int))) when () => 0 can do the same thing?

@zspitz
Copy link

zspitz commented Jan 9, 2021

A little late to the party, but:

@rikimaru0345 I've written a library that allows you to do this, and a Visual Studio debugging visualizer that leverages the library to display this for an expression tree at runtime.

Multiple renderers

@svick Being able to take the source code and convert it the compiler equivalent calls to factory methods is useful, but not always an option; specifically, when I don't have the source code of an expression tree, but only the runtime object.

@KirillOsenkov
Copy link
Owner

Wow @zspitz this is awesome!

@KirillOsenkov KirillOsenkov pinned this issue Jan 21, 2021
@KirillOsenkov
Copy link
Owner

I'll close this issue as this seems to be a great solution:
#50 (comment)

@davidfowl
Copy link
Contributor

zomg

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

5 participants