/// <summary> /// Adds the contents of another <see cref="PluginCollection">PluginCollection</see> to the end of the collection. /// </summary> /// <param name="value">A <see cref="PluginCollection">PluginCollection</see> containing the objects to add to the collection. </param> public void AddRange(PluginCollection value) { for (int i = 0; (i < value.Count); i = (i + 1)) { this.Add((IPlugin)value.List[i]); } }
/// <summary> /// Iterate through all the child nodes /// of the XMLNode that was passed in and create instances /// of the specified Types by reading the attribite values of the nodes /// we use a try/Catch here because some of the nodes /// might contain an invalid reference to a plugin type /// </summary> /// <param name="parent"></param> /// <param name="configContext"></param> /// <param name="section">The XML section we will iterate against</param> /// <returns></returns> public object Create(object parent, object configContext, System.Xml.XmlNode section) { PluginCollection plugins = new PluginCollection(); foreach(XmlNode node in section.ChildNodes) { try { //Use the Activator class's 'CreateInstance' method //to try and create an instance of the plugin by //passing in the type name specified in the attribute value object plugObject = Activator.CreateInstance(Type.GetType(node.Attributes["type"].Value)); //Cast this to an IPlugin interface and add to the collection IPlugin plugin = (IPlugin)plugObject; plugins.Add(plugin); } catch(Exception e) { //Catch any exceptions //but continue iterating for more plugins } } return plugins; }
private void LoadPlugins() { //Retrieve a plugin collection using our custom Configuration section handler m_plugins = (PluginCollection )ConfigurationSettings.GetConfig("plugins"); FillPluginMenu(); }
/// <summary> /// Initializes a new instance of the <see cref="PluginCollection">PluginCollection</see> class containing the elements of the specified source collection. /// </summary> /// <param name="value">A <see cref="PluginCollection">PluginCollection</see> with which to initialize the collection.</param> public PluginCollection(PluginCollection value) { this.AddRange(value); }
/// <summary> /// Initializes a new instance of the <see cref="PluginCollectionEnumerator">PluginCollectionEnumerator</see> class referencing the specified <see cref="PluginCollection">PluginCollection</see> object. /// </summary> /// <param name="mappings">The <see cref="PluginCollection">PluginCollection</see> to enumerate.</param> public PluginCollectionEnumerator(PluginCollection mappings) { _temp = ((IEnumerable)(mappings)); _enumerator = _temp.GetEnumerator(); }