代码之家  ›  专栏  ›  技术社区  ›  Jason Jarrett

C(一般的一般)?

  •  4
  • Jason Jarrett  · 技术社区  · 16 年前

    有没有办法用C语言表达这个想法?(基本上是泛型类型的泛型类型)?

    public static class ExtensionSpike
    {
        public static IEnumerable<T> Where<TCollection<T>>(this TCollection<T> sourceCollection, Expression<Func<T, bool>> expr)
            where TCollection : class, IEnumerable<T>, INotifyCollectionChanged
        {
            throw new NotImplementedException();
        }
    }
    
    1 回复  |  直到 16 年前
        1
  •  5
  •   STW    16 年前

    一般的约束可能不是你想要的,但这基本上就是你想要的吗?这将集合限制为 IEnumerable<T> (尽管可以将IEnumerable交换为List/Collection/etc…)

    public static IEnumerable<T> Where<T, TCollection>(this TCollection sourceCollection, Expression<Func<T, bool>> expr)
    where TCollection : IEnumerable<T>, INotifyPropertyChanged
    {
        throw new NotImplementedException();
    }
    

    更新: 只是稍微改变了我的样本,以便更好地遵循这个方法——我很困惑,没有意识到你想要一个 Where() 方法,我假设它是您的泛型约束 where .