providercollector.cs

来自「YetAnotherForum.Net+ScrewTurnWiki中文完美汉化增」· CS 代码 · 共 65 行

CS
65
字号

using System;
using System.Collections.Generic;
using System.Text;
using ScrewTurn.Wiki.PluginFramework;

namespace ScrewTurn.Wiki {

	/// <summary>
	/// Implements a generic Provider Collector.
	/// </summary>
	/// <typeparam name="T">The type of the Collector.</typeparam>
	public class ProviderCollector<T> {

		/// <summary>
		/// The list of Providers.
		/// </summary>
		protected List<T> list;

		/// <summary>
		/// Initializes a new instance of the class.
		/// </summary>
		public ProviderCollector() {
			list = new List<T>();
		}

		/// <summary>
		/// Adds a Provider to the Collector.
		/// </summary>
		/// <param name="provider">The Provider to add.</param>
		public void AddProvider(T provider) {
			list.Add(provider);
		}

		/// <summary>
		/// Removes a Provider from the Collector.
		/// </summary>
		/// <param name="provider">The Provider to remove.</param>
		public void RemoveProvider(T provider) {
			list.Remove(provider);
		}

		/// <summary>
		/// Gets all the Providers.
		/// </summary>
		public T[] AllProviders {
			get { return list.ToArray(); }
		}

		/// <summary>
		/// Gets a Provider, searching for its Type Name.
		/// </summary>
		/// <param name="typeName">The Type Name.</param>
		/// <returns>The Provider, or null if the Provider was not found.</returns>
		public T GetProvider(string typeName) {
			for(int i = 0; i < list.Count; i++) {
				if(list[i].GetType().ToString().Equals(typeName)) return list[i];
			}
			return default(T);
		}

	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?