diegodfsd
10/18/2012 - 8:52 PM

dynamic message

dynamic message

 public class Message : DynamicObject
    {
        private IDictionary<string, string> attributes;

        protected Message(IDictionary<string, string> attributes)
        {
            this.attributes = attributes;
        }

        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            if(attributes.ContainsKey(binder.Name))
            {
                result = attributes[binder.Name];
                return true;
            }
            result = null;
            return false;
        }

        public override bool TrySetMember(SetMemberBinder binder, object value)
        {
            if(value != null)
            {
                attributes[binder.Name] = value.ToString();
            }
            
            return true;
        }
    }