Sunday, August 28, 2011

refactoring yesterday's mess

I have refactored the mess I made yesterday like so:

using System;

namespace MyApp.Helpers

{

   public class SearchParametersForFoo : AttributeNormalizationLayer

   {

      public string Name

      {

         get { return null; }

         set

         {

            Append("Name", value);

         }

      }

      

      public Int32? Number

      {

         get { return null; }

         set

         {

            Append("Number", value);

         }

      }

   }

}

 
 

The action:

[HttpPost]

public ActionResult Index(SearchParametersForFoo searchParametersForFoo)

{

   Hashtable hashTable = searchParametersForFoo.Collection;

   
more code follows...

 
 

The base class:

using System.Collections;

namespace MyApp.Helpers

{

   public class AttributeNormalizationLayer

   {

      public Hashtable Collection = new Hashtable();

      

      public void Append(string name, object value)

      {

         if (value != null)

         {

            Collection.Add(name, value.ToString());

         }

      }

   }

}

No comments:

Post a Comment