using System; using System.Collections.Generic; using System.Text; using ScrewTurn.Wiki.PluginFramework; namespace ScrewTurn.Wiki { /// /// Implements a generic Provider Collector. /// /// The type of the Collector. public class ProviderCollector { private List list; /// /// Initializes a new instance of the class. /// public ProviderCollector() { list = new List(3); } /// /// Adds a Provider to the Collector. /// /// The Provider to add. public void AddProvider(T provider) { lock(this) { list.Add(provider); } } /// /// Removes a Provider from the Collector. /// /// The Provider to remove. public void RemoveProvider(T provider) { lock(this) { list.Remove(provider); } } /// /// Gets all the Providers (copied array). /// public T[] AllProviders { get { lock(this) { return list.ToArray(); } } } /// /// Gets a Provider, searching for its Type Name. /// /// The Type Name. /// The Provider, or null if the Provider was not found. public T GetProvider(string typeName) { lock(this) { for(int i = 0; i < list.Count; i++) { if(list[i].GetType().FullName.Equals(typeName)) return list[i]; } return default(T); } } } }