public static object CreateComponent(Type type, string name) { XClass obj = new XClass(); obj.Site = new XTypeSite(obj); obj.Site.Name = name; obj.AssignType(type); obj.AssignValue(Activator.CreateInstance(type)); return(obj); }
public static IComponent CreateComponent(IDesignerLoaderHost host, Type type, string name) { if (typeof(IComponent).IsAssignableFrom(type)) { if (host != null) { INameCreationService cs = host.GetService(typeof(INameCreationService)) as INameCreationService; if (cs != null) { IVplNameService ns = cs as IVplNameService; if (ns != null) { ns.ComponentType = type; } } return(host.CreateComponent(type, name)); } else { IComponent ic = (IComponent)CreateObject(type); ic.Site = new XTypeSite(ic); ic.Site.Name = name; return(ic); } } if (host != null) { INameCreationService cs = host.GetService(typeof(INameCreationService)) as INameCreationService; if (cs != null) { IVplNameService ns = cs as IVplNameService; if (ns != null) { ns.ComponentType = typeof(XClass); } } XClass obj = (XClass)host.CreateComponent(typeof(XClass), name); obj.AssignType(type); obj.AssignValue(CreateObject(type)); return(obj); } else { XClass obj = new XClass(); obj.Site = new XTypeSite(obj); obj.Site.Name = name; obj.AssignType(type); obj.AssignValue(CreateObject(type)); return(obj); } }