N
not_a_commie
I have here some example code (below) that I believe should work fine.
However, I get the error
Error 1 The call is ambiguous between the following methods or
properties:
'TestExtensions.ExtensionsOne.AddFive<TestExtensions.One>(TestExtensions.One)'
and
'TestExtensions.ExtensionsTwo.AddFive<TestExtensions.One>(TestExtensions.One)'
C:\workspace\TestProjects\TestExtensions\TestExtensions\Program.cs
44 4 TestExtensions
It's as though the resolution of the extension functions ignores the
where clause on the functions. As a workaround I can call the function
statically. I just think this should be resolvable.
namespace TestExtensions
{
public interface IOne
{
int Int { get; set; }
}
public class One: IOne
{
public int Int { get; set; }
}
public interface ITwo
{
int Int { get; set; }
}
public class Two : IOne
{
public int Int { get; set; }
}
public static class ExtensionsOne
{
public static void AddFive<T>(this T obj) where T : IOne
{
obj.Int += 5;
}
}
public static class ExtensionsTwo
{
public static void AddFive<T>(this T obj) where T : ITwo
{
obj.Int += 5;
}
}
class Program
{
static void Main(string[] args)
{
var one = new One();
one.AddFive();
}
}
}
However, I get the error
Error 1 The call is ambiguous between the following methods or
properties:
'TestExtensions.ExtensionsOne.AddFive<TestExtensions.One>(TestExtensions.One)'
and
'TestExtensions.ExtensionsTwo.AddFive<TestExtensions.One>(TestExtensions.One)'
C:\workspace\TestProjects\TestExtensions\TestExtensions\Program.cs
44 4 TestExtensions
It's as though the resolution of the extension functions ignores the
where clause on the functions. As a workaround I can call the function
statically. I just think this should be resolvable.
namespace TestExtensions
{
public interface IOne
{
int Int { get; set; }
}
public class One: IOne
{
public int Int { get; set; }
}
public interface ITwo
{
int Int { get; set; }
}
public class Two : IOne
{
public int Int { get; set; }
}
public static class ExtensionsOne
{
public static void AddFive<T>(this T obj) where T : IOne
{
obj.Int += 5;
}
}
public static class ExtensionsTwo
{
public static void AddFive<T>(this T obj) where T : ITwo
{
obj.Int += 5;
}
}
class Program
{
static void Main(string[] args)
{
var one = new One();
one.AddFive();
}
}
}