public IComponent CreateComponent(Type componentClass, string name)
{
Console.WriteLine("Attempting to create component " + name);
//check arguments
if (componentClass == null)
{
throw new ArgumentNullException("componentClass");
}
if (!componentClass.IsSubclassOf(typeof(System.Web.UI.Control)) && componentClass != typeof(System.Web.UI.Control))
{
throw new ArgumentException("componentClass must be a subclass of System.Web.UI.Control, but is a " + componentClass.ToString(), "componentClass");
}
if (componentClass.IsSubclassOf(typeof(System.Web.UI.Page)))
{
throw new InvalidOperationException("You cannot directly add a page to the host. Use NewFile() instead");
}
//create the object
IComponent component = (IComponent)Activator.CreateInstance(componentClass);
//and add to container
container.Add(component, name);
//add to document, unless loading
if (RootDocument != null)
{
((Control)RootComponent).Controls.Add((Control)component);
RootDocument.AddControl((Control)component);
}
//select it
ISelectionService sel = this.GetService(typeof(ISelectionService)) as ISelectionService;
if (sel != null)
{
sel.SetSelectedComponents(new IComponent[] { component });
}
return(component);
}