关于我想要理解的程序集依赖性有一个微妙的观点.我有一个项目,通过自定义包装器使用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类型参数的未使用的方法则不然?