How can I implement NotOfType in LINQ that has a nice calling syntax?

前端 未结 7 1182
轻奢々
轻奢々 2020-12-11 00:24

I\'m trying to come up with an implementation for NotOfType, which has a readable call syntax. NotOfType should be the complement to OfType&l

7条回答
  •  感情败类
    2020-12-11 01:00

    How about

    animals.NotOf(typeof(Giraffe));
    

    Alternatively, you can split the generic parameters across two methods:

    animals.NotOf().Type();
    
    public static NotOfHolder NotOf(this IEnumerable source);
    
    public class NotOfHolder : IHideObjectMembers {
        public IEnumerable NotOf();
    }
    

    Also, you need to decide whether to also exclude inherited types.

提交回复
热议问题