I have the following methods
public static EnumerableAssertions<T> AssertThat<T>(IEnumerable<T> collection)
{
Debug.WriteLine("Enumerable!");
return new EnumerableAssertions<T>(collection);
}
public static ObjectAssertions<T> AssertThat<T>(T value) where T : class
{
Debug.WriteLine("Generic fallback!");
return new ObjectAssertions<T>(value);
}
But why does the following call resolve to the generic fallback?
List<object> list = null;
AssertThat(list);
From my understanding the overload for IEnumerable<T>
should be more specific than the generic T : class
but C# seems to see that differently. If I add an overload for the exact type List<T>
it works just fine, but of course I don't want to add specific overloads for every type inheriting IEnumerable<T>