One of the code smells that particularly bothers me (though I often find myself doing it anyhow) is when I defensively program against nulls in C# (though could be any other language). That is, I do something like the following var rec = getRecord(..); if (rec != null) { var rec1 = getAnotherRecord(..); if (rec1 != null) { rec2 = getAThridRecord(..); if (rec2 != null)... The code gets ugly quick and the nesting does not help the readability, and if anything, hurts it. Today, while using a daily build of Resharper7, I noticed that when I asked resharper to do the null check for me, instead of doing the above, it did the following: var rec = getRecord(..); Debug.Assert(rec != null,"rec != … Continue Reading
Building a Simple Window Service Application in Visual Studio 2010 That Runs, Sleeps and Stops

Introduction The goal is to create a simple Service in Windows 7 (or other similar OS’s) with Visual Studio 2010 that simply starts, sleeps for 15 seconds, then stops. I realize this is not that useful, but basically, it covers the case of building a service that actually does something and when finished stops. In my personal case, my thread has a while(true) loop which keeps looking for new work and only completes when certain conditions are met (like a fatal error that is non recoverable). Microsoft has given us a pretty good set of docs and walk through. You can find them all here: http://msdn.microsoft.com/en-us/library/y817hyb6.aspx The Steps Create a new Visual Studio Project of type “Windows … Continue Reading
Test First Development Walk Through with Visual Studio 2011 Preview

Introduction Many of us know we should be using test first development, however it is hard to break old habits. I have to admit, I started to solve this particular problem I’m going to use an an example first without test first, then realized what a pickle I was going to be in proving to myself it worked. So, I thought, why not blog my experience as I do it. Using Visual Studio unit testing makes this pretty easy. The Problem I’m currently building a multithreaded email processor and part of that process is I have to figure out, for any given use whether they are supposed to have there email server checked. So, the way I look at it, I need a method that takes in the following parameter. … Continue Reading
Using The DataContext In EntityFramework To Retrieve Nested Objects

I’m always somewhat amazed when I read something from documentation that is not straight forward and it actually works. So amazed and excited that I often feel the need to blog about it. So, here is the problem. I created a CodeFirst implementation of EntityFramework in Visual Studio and created a simple hierarchy in my data model. That is, without showing all the code, here is what I have: public class Person{ [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int Id { get; set; } public virtual List<EmailAddressInfo> EmailAddressInfoList { get; set; } ..}public class EmailAddressInfo{ [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public … Continue Reading