C#的泛型方法解析

2019-12-30 15:03:36刘景俊

     (2).KeyedByTypeCollection:提供一个集合,该集合的项是用作键的类型。


  [__DynamicallyInvokable]
 public class KeyedByTypeCollection<TItem> : KeyedCollection<Type, TItem>
 {
 /// <summary>
 /// 初始化 <see cref="T:System.Collections.Generic.KeyedByTypeCollection`1"/> 类的新实例。
 /// </summary>
 public KeyedByTypeCollection();
 /// <summary>
 /// 根据指定的对象枚举初始化 <see cref="T:System.Collections.Generic.KeyedByTypeCollection`1"/> 类的新实例。
 /// </summary>
 /// <param name="items">泛型类型 <see cref="T:System.Object"/> 的 <see cref="T:System.Collections.Generic.IEnumerable`1"/>,用于初始化集合。</param><exception cref="T:System.ArgumentNullException"><paramref name="items"/> 为 null。</exception>
 public KeyedByTypeCollection(IEnumerable<TItem> items);
 /// <summary>
 /// 返回集合中第一个具有指定类型的项。
 /// </summary>
 /// 
 /// <returns>
 /// 如果为引用类型,则返回类型 <paramref name="T"/> 的对象;如果为值类型,则返回类型 <paramref name="T"/> 的值。 如果集合中不包含类型 <paramref name="T"/> 的对象,则返回类型的默认值:如果是引用类型,默认值为 null;如果是值类型,默认值为 0。
 /// </returns>
 /// <typeparam name="T">要在集合中查找的项的类型。</typeparam>
 [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
 public T Find<T>();
 /// <summary>
 /// 从集合中移除具有指定类型的对象。
 /// </summary>
 /// 
 /// <returns>
 /// 从集合中移除的对象。
 /// </returns>
 /// <typeparam name="T">要从集合中移除的项的类型。</typeparam>
 [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
 public T Remove<T>();
 /// <summary>
 /// 返回 <see cref="T:System.Collections.Generic.KeyedByTypeCollection`1"/> 中包含的类型 <paramref name="T"/> 的对象的集合。
 /// </summary>
 /// 
 /// <returns>
 /// 一个类型 <paramref name="T"/> 的 <see cref="T:System.Collections.ObjectModel.Collection`1"/>,包含来自原始集合的类型 <paramref name="T"/> 的对象。
 /// </returns>
 /// <typeparam name="T">要在集合中查找的项的类型。</typeparam>
 [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
 public Collection<T> FindAll<T>();
 /// <summary>
 /// 从集合中移除所有具有指定类型的元素。
 /// </summary>
 /// 
 /// <returns>
 /// <see cref="T:System.Collections.ObjectModel.Collection`1"/>,包含来自原始集合的类型 <paramref name="T"/> 的对象。
 /// </returns>
 /// <typeparam name="T">要从集合中移除的项的类型。</typeparam>
 [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
 public Collection<T> RemoveAll<T>();
 /// <summary>
 /// 获取集合中包含的某个项的类型。
 /// </summary>
 /// 
 /// <returns>
 /// 集合中指定的 <paramref name="item"/> 的类型。
 /// </returns>
 /// <param name="item">集合中要检索其类型的项。</param><exception cref="T:System.ArgumentNullException"><paramref name="item"/> 为 null。</exception>
 [__DynamicallyInvokable]
 protected override Type GetKeyForItem(TItem item);
 /// <summary>
 /// 在集合中的特定位置插入一个元素。
 /// </summary>
 /// <param name="index">从零开始的索引,应在该位置插入 <paramref name="item"/>。</param><param name="item">要在集合中插入的对象。</param><exception cref="T:System.ArgumentNullException"><paramref name="item"/> 为 null。</exception>
 [__DynamicallyInvokable]
 protected override void InsertItem(int index, TItem item);
 /// <summary>
 /// 使用一个新对象替换指定索引处的项。
 /// </summary>
 /// <param name="index">要替换的 <paramref name="item"/> 的从零开始的索引。</param><param name="item">要添加到集合中的对象。</param><exception cref="T:System.ArgumentNullException"><paramref name="item"/> 为 null。</exception>
 [__DynamicallyInvokable]
 protected override void SetItem(int index, TItem item);
 }