Survey - Who here uses System.Linq.Expressions to build Lambdas?
-
*grin* It is nasty because the code is a tangled mess itself or is it just the interconnectedness of it all?
A bit of both really. It replaced a CodeDOM module that we had - the problem is, we attempted to go feature for feature with the CodeDOM stuff, rather than taking the time to revisit the whole architecture. Now it's so convoluted that I don't want to touch it. Sooner or later we'll have to bite the bullet, but there are other more pressing things to work on first, and I really don't want to divert resources to this just in case they become suicidal.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier
-
(Same question I asked Phil) If using Expressions was easier, would you likely use it over Emit? If not, what is the reason for your usage of Emit vs. Expressions?
-
I wrote this code under .Net 1.1. I'm not sure Expressions can build delegates, though, can it? And yeah I'd use anything over Emit that did the same job. Writing out IL opcodes is not at all fast or easy!
Yes, Expressions can build delegates (typed even). Take a look at this[^]. The reason for this survey is that I've developed an open source API to make expressions easier. I'm just trying to gauge how useful it would be to the community at large. Once I've added some unit tests, I'll put together an article and post it on CodeProject. :D
-
Yes, Expressions can build delegates (typed even). Take a look at this[^]. The reason for this survey is that I've developed an open source API to make expressions easier. I'm just trying to gauge how useful it would be to the community at large. Once I've added some unit tests, I'll put together an article and post it on CodeProject. :D
I'll certainly take a look at it.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier
-
If using Expressions was easier, would you likely use it over CodeDom? If not, what is the reason for your usage of CodeDom vs. Expressions?
The short answer is that I couldn't figure out a way for Expressions to write out c# code to a file.
-
I'm just curious, so I wanted to take a quick poll to see how many people have actually used or are currently using System.Linq.Expressions[^]? Basically, have you written code like this in your life (courtesy of MSDN[^])?
// Add the following directive to the file:
// using System.Linq.Expressions;// An expression that represents the switch value.
ConstantExpression switchValue = Expression.Constant(3);// This expression represents a switch statement
// that has a default case.
SwitchExpression switchExpr =
Expression.Switch(
switchValue,
Expression.Call(
null,
typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }),
Expression.Constant("Default")
),
new SwitchCase[] {
Expression.SwitchCase(
Expression.Call(
null,
typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }),
Expression.Constant("First")
),
Expression.Constant(1)
),
Expression.SwitchCase(
Expression.Call(
null,
typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }),
Expression.Constant("Second")
),
Expression.Constant(2)
)
}
);// The following statement first creates an expression tree,
// then compiles it, and then runs it.
Expression.Lambda(switchExpr).Compile()();// This code example produces the following output:
//
// DefaultUpdate: For those that use other techniques (CodeDom, Emit, etc.), would you use Expressions more if it was easier to use? If not, why would you choose to stay with your current technique?
I tried something like that, but failed, so I bought a book on LINQ and haven't had a chance to read it yet. That is some confusing stuff.
-
The short answer is that I couldn't figure out a way for Expressions to write out c# code to a file.
You needed to write it out to a file?
-
I'll certainly take a look at it.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier
The link or the API I'm referring to? :D
-
I tried something like that, but failed, so I bought a book on LINQ and haven't had a chance to read it yet. That is some confusing stuff.
-
Certainly looks useful! I'll tuck that away for whenever I get back to doing complex LINQ stuff. :)
-
I'm just curious, so I wanted to take a quick poll to see how many people have actually used or are currently using System.Linq.Expressions[^]? Basically, have you written code like this in your life (courtesy of MSDN[^])?
// Add the following directive to the file:
// using System.Linq.Expressions;// An expression that represents the switch value.
ConstantExpression switchValue = Expression.Constant(3);// This expression represents a switch statement
// that has a default case.
SwitchExpression switchExpr =
Expression.Switch(
switchValue,
Expression.Call(
null,
typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }),
Expression.Constant("Default")
),
new SwitchCase[] {
Expression.SwitchCase(
Expression.Call(
null,
typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }),
Expression.Constant("First")
),
Expression.Constant(1)
),
Expression.SwitchCase(
Expression.Call(
null,
typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }),
Expression.Constant("Second")
),
Expression.Constant(2)
)
}
);// The following statement first creates an expression tree,
// then compiles it, and then runs it.
Expression.Lambda(switchExpr).Compile()();// This code example produces the following output:
//
// DefaultUpdate: For those that use other techniques (CodeDom, Emit, etc.), would you use Expressions more if it was easier to use? If not, why would you choose to stay with your current technique?
Andrew Rissing wrote:
Basically, have you written code like this in your life
No.
Andrew Rissing wrote:
would you use Expressions more if it was easier to use?
No.
Andrew Rissing wrote:
If not, why would you choose to stay with your current technique?
The only common usage I have seen for linq is for database access. And I either generate code like that or use dynamic framework apis. The only other usages I have seen have all been of the "gee this is really cool so lets find some way to use it regardless of how inappropriate it is".
-
The link or the API I'm referring to? :D
The API.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier
-
The API.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier
I've finished adding features at this point, so it'll likely be 1-2 weeks before an article pops up here on the site [needs unit testing and minor bug fixes]. If you want I can message you when it comes out or you'll likely just stumble upon it in your normal flow of things.
-
I've finished adding features at this point, so it'll likely be 1-2 weeks before an article pops up here on the site [needs unit testing and minor bug fixes]. If you want I can message you when it comes out or you'll likely just stumble upon it in your normal flow of things.
Message me so I know - I sometimes miss things if I'm busy at work, and as this is year end, I'm going to be very busy for the next month.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier
-
I feel dirty for admitting that I have. There's a piece of code that we have that does this for generating messaging layers based on config that we pass in - it's a nasty piece of code that seemed cool at the time - now I'm afraid to touch it because of what it could break.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier
At one of my previous jobs there was a piece of code like that. It could be fired from any one of several events and even the most innocuousness change would break it beyond all recognition. The last change made to it was to allow upto six instead of four options. The whole thing when FUBAR and it took three weeks of very clever people, plus me, to work out WTF was happening. There was a magic number derived from a magic number from a config lookup that required the entire config to be re-written. :omg: It was a bitch-slut module and I hope the b'tard who wrote it rots in hell. When I left, there was pleading that I'd take the POS with me and support it as I was, by then, about the only person who understood it. It's still there and still in use and, as of last week, unchanged.
Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
-
Message me so I know - I sometimes miss things if I'm busy at work, and as this is year end, I'm going to be very busy for the next month.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier
Roger roger.
-
I'm just curious, so I wanted to take a quick poll to see how many people have actually used or are currently using System.Linq.Expressions[^]? Basically, have you written code like this in your life (courtesy of MSDN[^])?
// Add the following directive to the file:
// using System.Linq.Expressions;// An expression that represents the switch value.
ConstantExpression switchValue = Expression.Constant(3);// This expression represents a switch statement
// that has a default case.
SwitchExpression switchExpr =
Expression.Switch(
switchValue,
Expression.Call(
null,
typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }),
Expression.Constant("Default")
),
new SwitchCase[] {
Expression.SwitchCase(
Expression.Call(
null,
typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }),
Expression.Constant("First")
),
Expression.Constant(1)
),
Expression.SwitchCase(
Expression.Call(
null,
typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }),
Expression.Constant("Second")
),
Expression.Constant(2)
)
}
);// The following statement first creates an expression tree,
// then compiles it, and then runs it.
Expression.Lambda(switchExpr).Compile()();// This code example produces the following output:
//
// DefaultUpdate: For those that use other techniques (CodeDom, Emit, etc.), would you use Expressions more if it was easier to use? If not, why would you choose to stay with your current technique?
Yer, I'm using System.Linq.Expressions to build an expression tree for our policy and claim search screens. The end result is that I can have as complex of a where clause as I'd ever want to create that buildable through our front end. It really is a nice slick piece of code and it has worked flawlessly since I first created it. But if I had it to do over again, I wouldn't have used expressions. It was a pain in the ass to get working, and even I don't want to get back in there and touch it again. I can only imagine the next guys awe and/or horror when he opens that. I'd probably go with a more simple generation of a SQL where clause.