Skip to content

Instantly share code, notes, and snippets.

@diegodfsd
Created October 18, 2012 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diegodfsd/3914644 to your computer and use it in GitHub Desktop.
Save diegodfsd/3914644 to your computer and use it in GitHub Desktop.
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment