Skip to content

Instantly share code, notes, and snippets.

@pparadis
Created June 13, 2012 00:39
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 pparadis/2921048 to your computer and use it in GitHub Desktop.
Save pparadis/2921048 to your computer and use it in GitHub Desktop.
public class UrlDictionnary : DynamicObject
{
Dictionary<string, string> dictionary = new Dictionary<string, string>();
public int Count
{
get
{
return dictionary.Count;
}
}
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
var keyName = binder.Name.ToLower();
if(dictionary.ContainsKey(keyName))
{
result = dictionary[keyName];
return true;
}
result = null;
return false;
}
public override bool TrySetMember(SetMemberBinder binder, object value)
{
dictionary[binder.Name.ToLower()] = (string) value;
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment