Consider this code - two extension methods for an interface - one generic and one is not. This code is imported with a library AutoFixture and cannot be changed.
public interface IFixture
{
}
public static class FixtureFreezer
{
//this is a real method within AutoFixture. The code is simplified though
public static T Freeze<T>(this IFixture fixture) where T:new()
{
return new T();
}
//not a real method, added for test
public static int Foo(this IFixture fixture)
{
return 0;
}
}
Now I wanted to create an overload for Freeze<T>
. However this results in a recursive call - fixture.Freeze<T>()
uses the params overload with empty array as params and not the parameterless overload.
public static class FixtureExtensions
{
public static T Freeze<T>(this IFixture fixture, params object[] arguments)
{
// do something
return fixture.Freeze<T>(); //recursion
}
public static int Foo(this IFixture fixture, params object[] arguments)
{
return fixture.Foo(); //no recursion
}
}
I have created the non-generic Foo
method for test and it is correctly resolved.
Is this behaviour correct? Can I somehow call the parameterless overload inside of my overload with params?
NOTE The simplified version does not reflect the real situation. To reproduce the problem please download AutoFixture.