public virtual ChoPlugInBuilder CreateBuilder() { Type type = ChoType.GetTypeFromXmlSectionName(GetType().Name); if (type == null) { throw new ChoPlugInException("Can't find builder for '{0}' plugin.".FormatString(GetType().Name)); } ChoPlugInBuilder builder = ChoActivator.CreateInstance(type) as ChoPlugInBuilder; if (builder == null) { throw new ChoPlugInException("Can't find builder for '{0}' plugin.".FormatString(GetType().Name)); } InitializeBuilder(builder); return(builder); }
private void btnAddNewPlugIn_Click(object sender, EventArgs e) { KeyValuePair <string, Type> keyValuePair = (KeyValuePair <string, Type>)cmbAvailPlugIns.SelectedItem; if (keyValuePair.Value == null) { return; } ChoPlugInBuilder builder = ChoActivator.CreateInstance(keyValuePair.Value) as ChoPlugInBuilder; if (builder == null) { return; } builder.Name = "{0}_{1}".FormatString(ChoPlugInBuilder.GetPlugInName(builder.GetType()), NextIndex()); AddNewBuilder(builder); }
public void Load(string[] types) { if (types == null) { return; } foreach (string typeString in types) { if (typeString.IsNullOrWhiteSpace()) { continue; } foreach (string typeText in typeString.SplitNTrim()) { try { Type type = ChoType.GetType(typeText); if (type == null) { continue; } IChoPlugIn <T> plugIn = ChoActivator.CreateInstance <IChoPlugIn <T> >(); if (plugIn != null) { _plugInsObjs.Add(plugIn); } } catch (Exception ex) { ChoTrace.Write(ex); } } } }
public ChoPlugInBuilder() { _plugInBuilderProperty = new Lazy <ChoPlugInBuilderProperty>(() => { ChoPlugInAttribute plugInAttribute = ChoType.GetAttribute <ChoPlugInAttribute>(GetType()); if (plugInAttribute == null) { throw new ChoPlugInException("Missing ChoPlugInAttribute decorated for '{0}' plugin builder.".FormatString(GetType().Name)); } Type type = plugInAttribute.PlugInBuilderPropertyType; if (type == null) { throw new ChoPlugInException("Can't find plugin property for '{0}' plugin builder.".FormatString(GetType().Name)); } ChoPlugInBuilderProperty p = ChoActivator.CreateInstance(type) as ChoPlugInBuilderProperty; if (p == null) { throw new ChoPlugInException("Can't find plugin property for '{0}' plugin builder.".FormatString(GetType().Name)); } try { InitPlugInBuilderProperty(p); } catch { } p.PropertyChanged += ((s, e) => { ApplyPropertyValues(p, e.PropertyName); }); return(p); }, true); }