Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

RouteValueDictionary

By: a guest on Mar 4th, 2010  |  syntax: C#  |  size: 4.08 KB  |  views: 1,393  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
  2. public class RouteValueDictionary : IDictionary<string, object>, ICollection<KeyValuePair<string, object>>, IEnumerable<KeyValuePair<string, object>>, IEnumerable
  3. {
  4.     // Fields
  5.     private Dictionary<string, object> _dictionary;
  6.  
  7.     // Methods
  8.     public RouteValueDictionary()
  9.     {
  10.         this._dictionary = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
  11.     }
  12.  
  13.     public RouteValueDictionary(IDictionary<string, object> dictionary)
  14.     {
  15.         this._dictionary = new Dictionary<string, object>(dictionary, StringComparer.OrdinalIgnoreCase);
  16.     }
  17.  
  18.     public RouteValueDictionary(object values)
  19.     {
  20.         this._dictionary = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
  21.         this.AddValues(values);
  22.     }
  23.  
  24.     public void Add(string key, object value)
  25.     {
  26.         this._dictionary.Add(key, value);
  27.     }
  28.  
  29.     private void AddValues(object values)
  30.     {
  31.         if (values != null)
  32.         {
  33.             foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(values))
  34.             {
  35.                 object obj2 = descriptor.GetValue(values);
  36.                 this.Add(descriptor.Name, obj2);
  37.             }
  38.         }
  39.     }
  40.  
  41.     public void Clear()
  42.     {
  43.         this._dictionary.Clear();
  44.     }
  45.  
  46.     public bool ContainsKey(string key)
  47.     {
  48.         return this._dictionary.ContainsKey(key);
  49.     }
  50.  
  51.     public bool ContainsValue(object value)
  52.     {
  53.         return this._dictionary.ContainsValue(value);
  54.     }
  55.  
  56.     public Dictionary<string, object>.Enumerator GetEnumerator()
  57.     {
  58.         return this._dictionary.GetEnumerator();
  59.     }
  60.  
  61.     public bool Remove(string key)
  62.     {
  63.         return this._dictionary.Remove(key);
  64.     }
  65.  
  66.     void ICollection<KeyValuePair<string, object>>.Add(KeyValuePair<string, object> item)
  67.     {
  68.         this._dictionary.Add(item);
  69.     }
  70.  
  71.     bool ICollection<KeyValuePair<string, object>>.Contains(KeyValuePair<string, object> item)
  72.     {
  73.         return this._dictionary.Contains(item);
  74.     }
  75.  
  76.     void ICollection<KeyValuePair<string, object>>.CopyTo(KeyValuePair<string, object>[] array, int arrayIndex)
  77.     {
  78.         this._dictionary.CopyTo(array, arrayIndex);
  79.     }
  80.  
  81.     bool ICollection<KeyValuePair<string, object>>.Remove(KeyValuePair<string, object> item)
  82.     {
  83.         return this._dictionary.Remove(item);
  84.     }
  85.  
  86.     IEnumerator<KeyValuePair<string, object>> IEnumerable<KeyValuePair<string, object>>.GetEnumerator()
  87.     {
  88.         return this.GetEnumerator();
  89.     }
  90.  
  91.     IEnumerator IEnumerable.GetEnumerator()
  92.     {
  93.         return this.GetEnumerator();
  94.     }
  95.  
  96.     public bool TryGetValue(string key, out object value)
  97.     {
  98.         return this._dictionary.TryGetValue(key, out value);
  99.     }
  100.  
  101.     // Properties
  102.     public int Count
  103.     {
  104.         get
  105.         {
  106.             return this._dictionary.Count;
  107.         }
  108.     }
  109.  
  110.     public object this[string key]
  111.     {
  112.         get
  113.         {
  114.             object obj2;
  115.             this.TryGetValue(key, out obj2);
  116.             return obj2;
  117.         }
  118.         set
  119.         {
  120.             this._dictionary[key] = value;
  121.         }
  122.     }
  123.  
  124.     public Dictionary<string, object>.KeyCollection Keys
  125.     {
  126.         get
  127.         {
  128.             return this._dictionary.Keys;
  129.         }
  130.     }
  131.  
  132.     bool ICollection<KeyValuePair<string, object>>.IsReadOnly
  133.     {
  134.         get
  135.         {
  136.             return this._dictionary.IsReadOnly;
  137.         }
  138.     }
  139.  
  140.     ICollection<string> IDictionary<string, object>.Keys
  141.     {
  142.         get
  143.         {
  144.             return this._dictionary.Keys;
  145.         }
  146.     }
  147.  
  148.     ICollection<object> IDictionary<string, object>.Values
  149.     {
  150.         get
  151.         {
  152.             return this._dictionary.Values;
  153.         }
  154.     }
  155.  
  156.     public Dictionary<string, object>.ValueCollection Values
  157.     {
  158.         get
  159.         {
  160.             return this._dictionary.Values;
  161.         }
  162.     }
  163. }