Saturday, May 11, 2013

What is considered 'too much' logic in a class constructor?

OK,


I have one solution. I generally avoid Switch statement in C# world.


What I have been able to achieve is:


1. Create your custom "attribute" (C# reference)


2. Decorate each of your Enumeration Field with this attribute.


3. When decorating using attribute, you will specify the action to be taken in Attribute.


4. In your class, you will examine the "Attribute Value" REGARDLESS of which Enumeration value is passed.


And, then use Reflection to complete the action. This way your code is extensible and "SAFE".


Viral.




MCTS - WPF, WinForms, Sql Server 2008


No comments:

Post a Comment