CSharpFeeds - All your C# feeds in one place.

Sponsors

Thursday, February 21, 2008

LambdaExpression - source code would be nice

by skeet via Jon Skeet's Coding Blog : C# on 2/21/2008 10:19:59 PM

Just taking a quick break from proof-reading to post a thought I had yesterday. Visual LINQ uses ToString() to convert an expression tree's body into readable text. In some cases it works brilliantly, reproducing the original source code exactly - but in other cases it's far from useful. For instance, from this expression tree representation:

(Convert(word.get_Chars(0)) = 113)

I suspect you wouldn't have guessed that the original code was:

word[0] == 'q'

Personally I don't find it terrifically obvious, even though I can see how it works. Here's a thought though - suppose the LambdaExpression class had a Source property which the compiler could optionally provide as a constructor argument, so that you could get at the original source code if you needed it. The use in Visual LINQ is obvious, but would it be useful elsewhere?

Well, suppose that LINQ to SQL couldn't translate a particular query expression into SQL. Wouldn't it be nice if it could report the part of the query expression it was having trouble with in the language it was originally written in? So a VB expression would give source in VB, a C# expression would give source in C# etc.

All of this would have to be optional, and I suspect some people would have intellectual property concerns about their source leaking out (most of which would be silly, due to the logic effectively being available with a call to ToString() anyway). I think it would be quite handy in a few situations though.

email it!bookmark it!digg it!

Original Post: LambdaExpression - source code would be nice

Subscribe

New Feed

Product Spotlight

Recently Updated Sources

Legal Note

The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.

Advertise with us