Closed rikimaru0345 closed 3 years ago
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
.
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.
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?
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.
@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.
Wow @zspitz this is awesome!
I'll close this issue as this seems to be a great solution: https://github.com/KirillOsenkov/RoslynQuoter/issues/50#issuecomment-757342066
zomg
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" :smile: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. :smile: