What is the "dispatcher" pattern and how would I implement it in code?
I have a property bag of generic objects and would like to have the retrieval delegated to a generic method.
Currently, I have properties looking for a specific key in the bag. For example:
private Dictionary<String, Object> Foo { get; set; }
private const String WidgetKey = "WIDGETKEY";
public Widget? WidgetItem
{
get
{
return Foo.ContainsKey(WidgetKey) ? Foo[WidgetKey] as Widget: null;
}
set
{
if (Foo.ContainsKey(WidgetKey))
Foo[WidgetKey] = value;
else
Foo.Add(WidgetKey, value);
}
}
It was suggested that this could be more generic with the "dispatcher" pattern, but I've been unable to find a good description or example.
I'm looking for a more generic way to handle the property bag store/retrieve.