Есть класс, который я не контролирую, который выглядит следующим образом:
Код: Выделить всё
namespace OtherCompany
{
public class ClassIDoNotControl
{
public void SomeMethod(string argument)
{
Console.WriteLine((new StackFrame(1).GetMethod().Name));
}
}
}
Код: Выделить всё
interface IInterfaceIDoControl
{
void SomeMethod(string argument);
}
class ClassIDoControl : OtherCompany.ClassIDoNotControl, IInterfaceIDoControl
{
}
Код: Выделить всё
namespace MyCompany
{
class Program
{
static void Main(string[] args)
{
IInterfaceIDoControl i = new ClassIDoControl();
i.SomeMethod("Hello World!"); // Prints "Main"
}
}
}
Причина в том, что под прикрытием компилятор C# меняет "ClassIDoControl" ", чтобы выглядеть так:
Код: Выделить всё
class ClassIDoControl : OtherCompany.ClassIDoNotControl, IInterfaceIDoControl
{
void IInterfaceIDoControl.SomeMethod(string argument)
{
base.SomeMethod(argument);
}
}
Подробнее здесь: https://stackoverflow.com/questions/366 ... ementation
Мобильная версия