开发者

C# (Generic of a Generic)?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜