using System;
interface A { void Foo(); }
interface B { void Foo(); }
interface C { void Foo(); }
class D : A, B, C {
public void Foo() { Console.WriteLine("pub fn"); }
void A.Foo() { Console.WriteLine("spec fun A"); }
void B.Foo() { Console.WriteLine("spec fun B"); }
}
public class Test
{
public static void Main()
{
var c = new D();
c.Foo();
((A)c).Foo();
((B)c).Foo();
((C)c).Foo();
// The call is ambiguous between the following methods or properties: `AExtensions.FooMeTwice(this A)' and `BExtensions.FooMeTwice(this B)'
// c.FooMeTwice();
Console.WriteLine("Using extension:");
((A)c).FooMeTwice();
((B)c).FooMeTwice();
}
}
public static class AExtensions
{
internal static void FooMeTwice(this A a) {
a.Foo();
a.Foo();
}
}
public static class BExtensions
{
internal static void FooMeTwice(this B b) {
Console.Write("What: ");
b.Foo();
}
}
dXNpbmcgU3lzdGVtOwoKaW50ZXJmYWNlIEEgeyB2b2lkIEZvbygpOyB9CmludGVyZmFjZSBCIHsgdm9pZCBGb28oKTsgfQppbnRlcmZhY2UgQyB7IHZvaWQgRm9vKCk7IH0KCmNsYXNzIEQgOiBBLCBCLCBDIHsgCglwdWJsaWMgdm9pZCBGb28oKSB7IENvbnNvbGUuV3JpdGVMaW5lKCJwdWIgZm4iKTsgfSAgCgl2b2lkIEEuRm9vKCkgeyBDb25zb2xlLldyaXRlTGluZSgic3BlYyBmdW4gQSIpOyB9Cgl2b2lkIEIuRm9vKCkgeyBDb25zb2xlLldyaXRlTGluZSgic3BlYyBmdW4gQiIpOyB9Cn0KCnB1YmxpYyBjbGFzcyBUZXN0CnsKCXB1YmxpYyBzdGF0aWMgdm9pZCBNYWluKCkKCXsKCQl2YXIgYyA9IG5ldyBEKCk7CgkJYy5Gb28oKTsKCQkKCQkoKEEpYykuRm9vKCk7CgkJKChCKWMpLkZvbygpOwoJCSgoQyljKS5Gb28oKTsKCQkKCQkvLyBUaGUgY2FsbCBpcyBhbWJpZ3VvdXMgYmV0d2VlbiB0aGUgZm9sbG93aW5nIG1ldGhvZHMgb3IgcHJvcGV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