我想.IsEmpty()
为 ICollection 和 IReadonlyCollection 接口编写一个扩展方法(例如):
public static bool IsEmpty<T>(this IReadOnlyCollection<T> collection)
{
return collection == null || collection.Count == 0;
}
public static bool IsEmpty<T>(this ICollection<T> collection)
{
return collection == null || collection.Count == 0;
}
但是当我将它与实现两个接口的类一起使用时,我显然得到了“模棱两可的调用”。我不想打字myList.IsEmpty<IReadOnlyCollection<myType>>()
,我希望它只是myList.IsEmpty()
。
这可能吗?