我想了解关于程序集依赖关系的一个微妙点。我有一个通过自定义包装器使用 SharpDX 的项目,如下所示:
SharpDX.dll <- Wrapper.dll <- Project.dll
Wrapper.dll 中的类型如下:
public class D3DWrapperTypeA {
//public D3DWrapperTypeA(SharpDX.Device device) {
//
//}
public D3DWrapperTypeA(IntPtr devicePointer) {
SharpDX.Device device = new SharpDX.Device(devicePointer);
// etc
}
}
在此类中,如果我取消注释已注释的构造函数,则 Project.dll 必须引用 SharpDX.dll,即使它不使用构造函数。
但是,我还有另一种包装器类型,如下所示:
public class WrapperTypeB {
public SharpDX.Device GetDevice(int adapter) {
// etc
}
public IntPtr GetDevicePointer(int adapter) {
return GetDevice(adapter).NativePointer;
}
}
而这里,只要我不实际使用返回 SharpDX 对象的 GetDevice 方法,Project.dll 就不需要引用 SharpDX.dll。
为什么即使是使用 SharpDX 类型参数的未使用构造函数也会导致对 SharpDX 的依赖,而返回 SharpDX 类型参数的未使用方法则不会?