title: Issue with convering from Silverlight HashTable to IDictionary
body: <p>I am currently updating some exising Silverlight code and moving helper classes into a Silverlight 5 library but I am struggling with the change from a HashTable implementation to a IDictionary implementation as shown below.</p>
  
  <p>This functionality allows the enumerations to be attributed allowing the looking up of a string value.</p>
  
  <p>The code compiles but fails on the <code>stringValues.Add(value, attrs[0]);</code> line in the <code>ParseEnumStrings</code> class with the below exception details.</p>
  
  <p>Any idea what I have done wrong in the conversion of the code?</p>
  
  <p><strong>Exception</strong></p>
  
  <pre><code>The value "Today" is not of type "System.Type" and cannot be used in this generic collection.
  Parameter name: key.
  
     at System.ThrowHelper.ThrowWrongKeyTypeArgumentException(Object key, Type targetType)
     at System.Collections.Generic.Dictionary`2.System.Collections.IDictionary.Add(Object key, Object value)
     at Silverlight.Helper.Enums.ParseEnumStrings.GetStringValue(Enum value) in Z:\Perforce\Development\Microsoft .Net\dotNet 4.0\Silverlight 5\Helper\Helper\Enums\ParseEnumStrings.cs:line 25
     at QSmartFaultsByZone.Web.Models.QSmartService.GetRTF(Int32 buID, String zones, ReportTimePeriod time) in Z:\Perforce\Development\Microsoft .Net\dotNet 4.0\Silverlight 5\QSmart Faults By Zone\QSmartFaultsByZone.Web\Models\QSmartService.cs:line 114
     at GetRTF(DomainService , Object[] )
     at System.ServiceModel.DomainServices.Server.ReflectionDomainServiceDescriptionProvider.ReflectionDomainOperationEntry.Invoke(DomainService domainService, Object[] parameters)
     at System.ServiceModel.DomainServices.Server.DomainOperationEntry.Invoke(DomainService domainService, Object[] parameters, Int32&amp; totalCount)
     at System.ServiceModel.DomainServices.Server.DomainService.Query(QueryDescription queryDescription, IEnumerable`1&amp; validationErrors, Int32&amp; totalCount)
  </code></pre>
  
  <p><strong>Enum</strong></p>
  
  <pre><code>public enum ReportTimePeriod 
  {
      [StringValue("Today")]
      Today = 0,
      [StringValue("Twenty Four Hours")]
      TwentyFourHours = 1,
      [StringValue("Week")]
      Week = 2,
      [StringValue("Month")]
      Month = 3
  }
  </code></pre>
  
  <p><strong>String Value Attribute</strong></p>
  
  <pre><code>public class StringValueAttribute : Attribute
  {
      private readonly string value;
  
      public StringValueAttribute(string value)
      {
          this.value = value;
      }
  
      public string Value
      {
          get { return this.value; }
      }
  }
  </code></pre>
  
  <p><strong>Legacy HashTable class</strong></p>
  
  <pre><code>public class ParseEnumStrings
  {
      private static Hashtable _stringValues = new Hashtable();
  
      public static string GetStringValue(Enum value)
      {
          string output = null;
          Type type = value.GetType();
  
          //Check first in our cached results...
          if (_stringValues.ContainsKey(value))
              output = (_stringValues[value] as StringValueAttribute).Value;
          else
          {
              //Look for our 'StringValueAttribute' 
              //in the field's custom attributes
              FieldInfo fi = type.GetField(value.ToString());
              StringValueAttribute[] attrs =fi.GetCustomAttributes(typeof(StringValueAttribute),false) as StringValueAttribute[];
              if (attrs.Length &gt; 0)
              {
                  _stringValues.Add(value, attrs[0]);
                  output = attrs[0].Value;
              }
          }
  
          return output;
      }
  </code></pre>
  
  <p><strong>New IDictionary implementation</strong></p>
  
  <pre><code>public class ParseEnumStrings
  {
      private static IDictionary stringValues = new Dictionary&lt;Type, StringValueAttribute&gt;();
  
      public static string GetStringValue(Enum value)
      {
          string result = string.Empty;
          Type type = value.GetType();
  
          if (stringValues.Contains(value))
              result=(stringValues[value] as StringValueAttribute).Value;
          else
          {
              FieldInfo f = type.GetField(value.ToString());
              StringValueAttribute[] attrs = f.GetCustomAttributes(typeof(StringValueAttribute), false) as StringValueAttribute[];
              if (attrs.Length &gt; 0)
              {
                  stringValues.Add(value, attrs[0]);
                  result = attrs[0].Value;
              }
          }
  
          return result;
      }
  }
  </code></pre>
  
  <p><strong>Implementation</strong></p>
  
  <pre><code>return (from rft in qs.spBusinessProductsRFTTodayV2(zones, buID, ParseEnumStrings.GetStringValue(time))
          select new RightFirstTimeReportDto
          {
              Builds=rft.Builds,
              BuildsWithFaults=rft.BuildsWithFaults,
              Name=rft.Name,
              RightFirstTime=rft.RFT,
              ZoneID=rft.ZoneID
          }).ToList();
  </code></pre>