我有一个定义了一些重载的接口的汇编A:
public interface ITransform
{
Point InverseTransform(Point point);
Rect InverseTransform(Rect value);
System.Drawing.Point InverseTransform(System.Drawing.Point point);
}
...还有一个汇编B引用了A(二进制文件,不是项目),并调用其中的一个重载版本:
var transform =
(other.Source.TransformToDisplay != null &&
other.Source.TransformToDisplay.Valid) ?
other.Source.TransformToDisplay : null;
if (transform != null)
{
e.Location = transform.InverseTransform(e.Location);
}
更准确地说,它调用了InverseTransform
方法的 System.Windows.Point
重载,因为e
中的Location
属性是该类型。但是,当我在IDE中构建B时,会出现以下错误:
尽管这甚至不是我正在调用的重载。当我注释掉调用重载方法error CS0012: The type 'System.Drawing.Point' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
InverseTransform
的行时,它能够正常构建,即使我仍然实例化了一个ITransform
类型的对象。为什么?有没有一种方法可以修复此问题而无需在各处添加对System.Drawing
的引用?
InverseTransform2
然后再试一下吗?我不知道答案,但我想知道它是否与重载决议有关。 - Sergey Kalinichenkoe.Location
是一个System.Windows.Point
对象,还是从System.Windows.Point
派生的另一个类? - Justin MorganSystem.Drawing.Point
是什么,它也不知道哪个重载是最特定于e.Location
的。假设System.Drawing.Point
是一个接口,并且e.Location
是实现该接口的派生类?那么第二个重载就是正确的选择。编译器是否知道e.Location
总是一个System.Windows.Point
? - Justin Morgan