.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()
。
これは可能ですか?