-
I'm currently writing the chapter about control templates in our WPF book , and I wanted to include a list of all of the named parts that are hidden away in the dark recesses of the various controls. Before I even started googling, I had an idea that I thought I'd share. For those of you not...
-
Don't get me wrong, I really like the Asp.Net Cache (or HttpRuntime.Cache or Uncle Daddy if you want to call it that... you're a little odd aren't you?), but sometimes it just can't be trusted. I mean, I just gave you (the cache) my precious object a second ago and now you claim you don't...
-
I've been burned by a few bugs recently due to swallowed exceptions. In case you don't know, empty catch blocks will hurt you. Really, they will. I wanted a way to locate all of the empty blocks in our code base, I was playing around with NDepend and the amazing Code Query Language , but it's...
-
I know this has been discussed before elsewhere - but since I'm cranky about finding it after not-so-few-minutes of looking in some legacy code I'm working on - what follows is NOT an example of proper exception handling: } catch (Exception ex) { AuditLogger.LogError(ex); } This "swallow...
-
Conditionals are a common spot for the unintended creation of un-maintainable and un-readable code. To mitigate complicated conditionals, refactoring with Decompose Conditional always helps in conveying what you're trying to do. In other times, it's simply a matter of making the conditional logic...
-
What is the best way to cast from one type to another in C#? This question came up at work last week while I was looking through some older code. The code in question was using the C style casting syntax. I have started to use the "as" style cast more often and rewrote it. Then I decided to...
-
Have you ever been to the microsoft.public.dotnet.languages.csharp newsgroup? If you have been there for more than a few moments you must have noticed an individual answering even the toughest C# questions like crazy, Jon Skeet . Jon is a C# MVP and maintains a blog and a collection of very interesting...
-
I started playing with StructureMap recently. I am struggling with how to design my code's interaction with StructureMap when it comes to the configuration and use of plugin keys. If you have any insights or experience with this, please let me know! 1. Configuration via StructureMap.config Pros : * Separation...
-
Problem : If you've ever tried to cast been list generics, you know that you can't. Example : 1. You have two classes Shape and Square, where Square inherits from Shape. 2. You have two generic lists, List<Shape> and List<Square>. 3. List<Square> does not inherit from List<Shape>...
-
The Problem Recently I ran into a need to keep a list of integers sorted in ascending order. The list was used as an internal representation of a set, so I didn't have to create a new class implementing IList<T> or anything similar. The whole issue was to implement adding new elements properly...
-
[Updated March 10, 2009: Important!! While the original content shown below is usable in most cases, there are scenarios wherein it breaks down. The results of GetHashCode should not also be used as the means for expressing object equality. Accordingly, this, and other issues have been resolved and may...
-
People are talking about Microsoft's Entity framework and how it does not currently allow persistence ignorant domain objects. I've been torn about this issue for a while now . On the one hand, having an O/R mapper that is persistent ignorant essentially means that it has to support XML mapping files...
-
It is a common occurrence wherein you may want to publicly expose a property's getter but internally restrict the setter. (The last refactoring challenge had a good use for this.) I regularly see people provide a publicly exposed property - with only a getter - and then add an internally available method...
-
I've been asked a couple of times how to give a domain object access to a dependency injection (DI) container, such as Castle Windsor, if the domain object is loaded via an ORM, such as NHibernate. There are two apparent ways to do this: 1) you can manually give the domain object access to the DI via...
-
If you're not familiar with the Refactor It! challenges, please read this post . (Yes, this one is quite a bit overdue.) Now on to challenge 3... Welcome back to another refactoring challenge! This challenge will pit your skills against the very useful State Design Pattern along with writing your own...