开发者

C# (Generic of a Generic)?

开发者 https://www.devze.com 2022-12-16 23:17 出处:网络
Is there any way to express this idea in C#? (Basically a generic type of a开发者_JAVA百科 generic type)?

Is there any way to express this idea in C#? (Basically a generic type of a开发者_JAVA百科 generic type)?

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();
    }
}


The generic constraint might not be quite what you want, but is this basically what you're looking for? This constrains TCollection to be an IEnumerable<T> (although IEnumerable can be swapped for 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();
}

Update: just changed my sample a little to better follow the method--I'd been confused and didn't realize you wanted a Where() method, I assumed it was your generic-constraint where.

0

精彩评论

暂无评论...
验证码 换一张
取 消