When writing code I think that it is important to keep in mind what type of code it is. Far too often, I see people writing very complicated structures without the need. I think that a reason for this is that the code was inspired from some library. Unless reading other people’s code for fun,… Continue reading Application Code vs Library Code
Category: C#
Using and Disposing of WCF Clients
Designing an interface always requires careful considerations of how it will be used. Scott Meyers elegantly catches the entire problem in one sentence in his book Effective C++: Make interfaces easy to use correctly and hard to use incorrectly. The people at Microsoft who were in charge for the WCF client code generation either hadn’t read… Continue reading Using and Disposing of WCF Clients
Traversing Expression Trees
The Expression<T> data type which was introduced together with LINQ is interesting. When a Func<TResult> is wrapped in an Expression<T> the code is no longer completely compiled, instead it is preserved as an expression tree that can be traversed during runtime. This is what the method ExpressionHelper.GetExpressionText() that I used in my last post Type Safe SelectList… Continue reading Traversing Expression Trees
Type Safe SelectList Factory
I think that ASP.NET MVC is a huge step forward from ASP.NET Web Forms. Still, there are some parts of it that are disappointing. One is the SelectList constructor, that doesn’t use generics and has string parameters for field selection. To create a SelectList from an IEnumerable<> we would do something like this. IEnumerable<Person> people… Continue reading Type Safe SelectList Factory
Catch Errors in ASP.NET MVC Views
The compiler is my friend. It helps me check for simple spelling mistakes and alerts me when a change in one part of the code base breaks a reference somewhere else. When developing in ASP.NET Web Forms I have had a hard time with the lack of compilation of aspx pages. As long as the… Continue reading Catch Errors in ASP.NET MVC Views