问题描述
我目前正在为 Inventor(3d 建模软件)开发一个插件。当您使用 api 时,有两种不同类型的文档
- 组装文件
- 部分文档
api 为我提供了一个返回所选文档的方法。
PartDocument part = ((PartDocument)application.ActiveDocument);
在运行时此演员表有效。编译器告诉我这是一个可疑的转换,因为“PartDocument”没有实现“application.ActiveDocument”返回的类型。
[TypeLibType(TypeLibTypeFlags.FDispatchable)]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
[Guid("xxxxxx")]
[DefaultMember("Type")]
[ComImport]
public interface PartDocument
{
....
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
[TypeLibType(TypeLibTypeFlags.FDispatchable)]
[Guid("xxxxx")]
[DefaultMember("Type")]
[ComImport]
public interface Application
{...
[DispId(50331905)]
_Document ActiveDocument { [DispId(50331905),MethodImpl(MethodImplOptions.PreserveSig | MethodImplOptions.InternalCall,MethodCodeType = MethodCodeType.Runtime)] [return: MarshalAs(UnmanagedType.Interface)] get; }
[Guid("xxxxxx")]
[CoClass(typeof (_DocumentClass))]
[ComImport]
public interface _Document : Document,_VbaImplementationEvents_Event
{
}
那为什么会这样呢?有人可以向我解释一下吗?
我该如何测试?
var documentMock =new Mock<PartDocument>();
var applicationMock = new Mock<Application>();
applicationMock.Setup(x => x.ActiveDocument).Returns(documentMock.Object);
编译器告诉我他不能从 'PartDocument' 转换为 '_Document' --> 这是真的,那么为什么它在运行时工作?
提前致谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)