Coming out of the habit of writing ifs/elseifs for every possible condition
<p>When parsing an xml document for its nodes or attributes, if the document is large, I would have a bunch of ifs and else statements.</p>

<p>Obviously, 100+ ifs does not make up maintainable code in the long run.</p>

<p>Rather than doing this, is there another better way? I read on Hanselman's blog about a friend of his who had the same situation and wrote loads of ifs/else if and generally poor code. Hanselman provided some snippets of a more maintainable way but the entire code isn't available so it's a little hard to understand exactly what (the whole picture) is going on. <a href="http://www.hanselman.com/blog/BackToBasicsLifeAfterIfForAndSwitchLikeADataStructuresReminder.aspx" rel="nofollow">Life after if, else</a></p>

<p>I am using .NET 3.5 SO I have the full power of extension methods and LINQ available to me. However, I use .NET 2.0 a work so would also appreciate any solutions in v2.0. :)</p>

<p>My code looks very similar to the problem on Hanselman's site:</p>

<p>if (xmlNode.Attributes["a"].Value == "abc"
 {  </p>

<p>}<br />
 else if (xmlNode.Attributes["b"].Value == "xyz"<br />
 {<br />
     wt = MyEnum.Haze;<br />
 }  </p>

<p>I could just have a dictionary storing the values I am looking for as keys and perhaps a delegate in the value (or whatever I want to happen on finding a required value), so I could say if (containskey) get delegate and execute it, in pseudocode.</p>

<p>This sort of thing goes on and on. Obviously very naive way of coding. I have the same problem with parsing a text document for values, etc.</p>

<p>Thanks</p>
