public IUserDefinedWidget Create(string widgetType, string id)
{
var type = Type.GetType(widgetType);
if (type == null)
{
throw new NotSupportedException("The widget type specified " + widgetType +
" is not found in any known type library.");
}
if (!typeof(IUserDefinedWidget).IsAssignableFrom(type))
{
throw new NotSupportedException("The widget type specified " + widgetType +
" is not a IUserDefinedWidget");
}
var widget = Activator.CreateInstance(type) as IUserDefinedWidget;
Debug.Assert(widget != null);
widget.Id = id;
var key = BuildMultiUseWidgetKey(widget);
if (this.cachedWidgets.ContainsKey(key))
{
throw new ArgumentException("A widget with this key already exists.", nameof(id));
}
var baseWidget = (Widget) widget;
this.cachedWidgets.Add(key, baseWidget);
return widget;
}