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
If you're going to make a method for inference, you want to infer all the way. That requires an example of each type:
public static class ExtMethods
{
public static IEnumerable NotOfType(this IEnumerable source)
{
return source.Where(t => !(t is U));
}
// helper method for type inference by example
public static IEnumerable NotOfSameType(
this IEnumerable source,
U example)
{
return source.NotOfType();
}
}
called by
List items = new List() { 1, 1.0m, 1.0 };
IEnumerable result = items.NotOfSameType(2);