Fundamentals

Fundamentals
I <3 LinqKit – Dynamically build arbitrarily complex Linq Queries

In some cases, I need to be able to build a query that has a variable set of OR conditions. This is not simple with the default language constructs and extension methods. It’s simple to dynamically build an expression that includes AND parameters, because that is what the WHERE() extension method does. Not so easy for OR’ing together a bunch of conditions. Enter LinqKit. This is a great library. It provides some easy to use (but powerful) extension methods that let you “Or()” some conditions together. A common case is where you get a list of values that you need to add into...

posted @ Wednesday, April 14, 2010 11:42 AM | Feedback (0)

NativeMethods classes are special

“Whatever doesn’t kill you makes you stronger” That’s how I feel about Code Analysis. It’s painful, but in the end, it teaches me stuff that I didn’t know or hadn’t thought about. Richard Broida challenged me to see if I could rework some WIN32 P/Invoke code to get it to pass Code Analysis rules. My initial response was pretty close to whining, but I recovered from my temper tantrum and did some investigation. Luckily, I didn’t have to look too far… The info on the rule “CA1060:MovePInvokesToNativeMethodsClass” provided some useful guidance and explanation. So I created a class in my project called...

posted @ Monday, March 15, 2010 3:07 PM | Feedback (0)

Who knew overriding GetHashCode() was so much fun?

So, I have a project with Code Analysis turned on and it treats warnings as errors. In this project, I have a class that overrides Equals() so that I can use some of the nice collection based linq expression (like Except()). Well, code analysis doesn’t like it if you override Equals, but forget to override GetHashCode(). Needless to say, I have to override GetHashCode(). But how does one do this? Some searching turned up a bunch of interesting resources showing how to do this. However, there isn’t some cut and paste code that solves the problem. You have...

posted @ Friday, March 05, 2010 2:23 PM | Feedback (0)