Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 25th, 2012  |  syntax: None  |  size: 0.78 KB  |  hits: 12  |  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. System.Dynamic ExpandoControl is it possible?
  2. <x:ExpandoControl someProperty="a value"></x:ExpandoControl>
  3.        
  4. public interface IAttributeAccessor
  5. {
  6.     string GetAttribute(string key);
  7.     void SetAttribute(string key, string value);
  8. }
  9.        
  10. public class ExpandoControl : Control, IAttributeAccessor
  11. {
  12.     IDictionary<string, object> _expando = new ExpandoObject();
  13.  
  14.     public dynamic Expando
  15.     {
  16.         {
  17.             return _expando;
  18.         }
  19.     }
  20.  
  21.     void IAttributeAccessor.SetValue(string key, string value)
  22.     {
  23.         _expando[key] = value;
  24.     }
  25.  
  26.     string IAttributeAccessor.GetValue(string key)
  27.     {
  28.         object value;
  29.         if (_expando.TryGetValue(key, out value) && value != null)
  30.             return value.ToString();
  31.         else
  32.             return null;
  33.     }
  34. }