Exemple #1
0
        /// <summary>
        /// Loads the plug-ins from the specific assembly.
        /// </summary>
        /// <param name="_assembly">The assembly which may contains the plug-ins.</param>
        /// <param name="_enabledForDefault">The default value if the plug-in is not found in the enabling list.</param>
        public virtual void Load(Assembly _assembly, bool _enabledForDefault)
        {
            try
            {
                Type[] types = _assembly.GetTypes();

                LoadEnabling();

                foreach (Type type in types)
                {
                    if (!type.IsSubclassOf(typeof(PluginBase <T>)))
                    {
                        continue;
                    }

                    object[] custAttributes = type.GetCustomAttributes(true);
                    foreach (object custAttr in custAttributes)
                    {
                        if (custAttr is U)
                        {
                            PluginBase <T> plugin = (PluginBase <T>)Activator.CreateInstance(type);
                            if (enablingHash__.Contains(plugin.Identifier))
                            {
                                plugin.Enabled = Convert.ToBoolean(enablingHash__[plugin.Identifier]);
                            }
                            else
                            {
                                plugin.Enabled = _enabledForDefault;
                            }
                            items__.Add(plugin);
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new PluginException("Failed to load plugin.", ex);
            }
        }
Exemple #2
0
 /// <summary>
 /// Removes the first occurrence of the item from the collection.
 /// </summary>
 /// <param name="item">The item to be removed.</param>
 /// <returns>True if the item was successfully removed from the collection. Otherwise, false.</returns>
 public bool Remove(PluginBase <T> item)
 {
     return(items__.Remove(item));
 }
Exemple #3
0
 /// <summary>
 /// Checks if a specific item exists in the collection.
 /// </summary>
 /// <param name="item">The item to be checked.</param>
 /// <returns>True if the item exists, otherwise false.</returns>
 public bool Contains(PluginBase <T> item)
 {
     return(items__.Contains(item));
 }
Exemple #4
0
 /// <summary>
 /// Adds a plugin to the plug-in collection.
 /// </summary>
 /// <param name="item">The item that is going to be added to the collection.</param>
 public void Add(PluginBase <T> item)
 {
     items__.Add(item);
 }