1

I'm using a tool that creates LambdaExpressions from a gui. I want the that expression as c# (or even compilable IL) so that I can combine it into an assembly for later executilon.

The Body property returns a string that looks like c# but uses constants like True and AndAlso instead of true and &&. I understand why.

Is there built in way to convert that LambdaExpression, or any implementation of Expression, to a *.dll?

This is the output of the Body property

((((x.Hospitalizations != null) AndAlso x.Hospitalizations.Any(x => Equals(x.TreatingPhysician, "Dr Ash Williams", OrdinalIgnoreCase))) == False) AndAlso (Convert(x.Pulse, Nullable`1) > Convert(50, Nullable`1)))

and from that LambdaExpression class I can, of course, get important things like the type and name of the object

kevcoder
  • 883
  • 1
  • 15
  • 29
  • Hello, Can you add example string of those lambda expressions? Overall, you probably need to write a parser class probably. I don't recall any built in way regarding for conversion of lambda expressions – AntiqTech Jan 26 '22 at 14:05
  • 1
    What does the GUI actually output? Can we see a paste or screenshot or something? – canton7 Jan 26 '22 at 14:43
  • 1
    you may have a look at https://github.com/zspitz/ExpressionTreeToString – Sohaib Jundi Jan 26 '22 at 14:55
  • Check this lib [ReadableExpressions](https://github.com/agileobjects/ReadableExpressions) – Svyatoslav Danyliv Jan 26 '22 at 15:07
  • I've updated the question with the string that I get from the Body property – kevcoder Jan 26 '22 at 19:05
  • But the `Body` property of *what*? What exactly do you get out of this tool? Can you show a screenshot of it giving you output? – canton7 Jan 27 '22 at 08:42
  • @canton7 check the link behind the word Body in the 2nd paragraph. It's the .net LambdaExpression class. – kevcoder Jan 27 '22 at 17:45
  • 1
    @MathiasR.Jessen not what I was hoping for, but yes that answers the question – kevcoder Jan 27 '22 at 17:55
  • @SohaibJundi Yes. I'll be checking that out. – kevcoder Jan 27 '22 at 17:57
  • Right, but how does a GUI tool **output** the LambdaExpression? Does it give you C# code to construct it, as text you can copy/paste? Does it show you what the DebugView is? Just it just show you something you can click through in the UI? I mean if it just gave you the C# to construct it this would be trivial: just paste that into your app, and call .Compile() on it at runtime, so it can't be that. So what is it? – canton7 Jan 27 '22 at 19:27
  • @canton7 I'm reflecting to get that LambdaExpression. I never said it output... "I'm using a tool that creates..." : ) – kevcoder Jan 27 '22 at 22:02
  • So what is your tool, and what does it create from its gui? I'm none the wiser – canton7 Jan 28 '22 at 08:38
  • @canton7 https://codeeffects.com/ – kevcoder Apr 01 '22 at 04:32
  • Something like [this](https://github.com/zspitz/ExpressionTreeVisualizer)? – Zev Spitz Sep 05 '22 at 21:22

0 Answers0