2

I'm looking for the library which provides the expression printing functionality (from the lambdas converted to expression trees). In other words it should do similar job to parsing examples here, but should be obviously far more complete. Is anyone aware of such library?

konrad.kruczynski
  • 46,413
  • 6
  • 36
  • 47
  • Why do you want to do that? How should the printed expressions look like? Isn't `ToString()` good enough for you? – svick Apr 28 '12 at 09:32
  • @svick: I'm not sure you've understood my question. Look at the examples in the link provided. – konrad.kruczynski Apr 28 '12 at 09:37
  • Why do you think I didn't understand your question? I looked at the example in the link, and it doesn't clarify what exactly you want. Could you answer my questions? – svick Apr 28 '12 at 09:42
  • @svick: I thought that because of the `ToString()` suggestion. I've started to edit the question and then I understood *which* `ToString()` you were talking about. Didn't know that the to string on the expression object just pretty prints the expression! ;) Post it as an answer to have it accepted. – konrad.kruczynski Apr 28 '12 at 09:46
  • possible duplicate of [convert-an-expression-tree-to-source-code-string](http://stackoverflow.com/questions/1402839/convert-an-expression-tree-to-source-code-string) – nawfal Dec 19 '13 at 19:32

1 Answers1

5

If you want some textual representation of the expression and you don't care how exactly does it look like, you can use ToString(). All of the Expression types override this method.

For example, for the simple expression num => num < 5, ToString() returns num => (num < 5). But for more complicated expressions, it doesn't look like C# code anymore. For example, for num => num < Math.Pow(5,5), it returns num => (Convert(num) < Pow(5, 5)).

svick
  • 236,525
  • 50
  • 385
  • 514