是否可以将System .__ ComObject强制转换为某种类型,仅在运行时才知道?我有以下代码
Type ComClassType = SomeDLLAssembly.GetType("ClassName");
dynamic comClassInstance = icf2.CreateInstanceLic(null, null, ComClassType.GUID, "License string");
//This will throw exception, because comClassInstance type is __ComObject and it does not contains ComClassMethod
comClassInstance.ComClassMethod();
Run Code Online (Sandbox Code Playgroud)
当我将使用下面的代码时,它工作正常,但不幸的是我不能在我的代码中使用InvokeMember,因为它会非常复杂.
ComClassType.InvokeMember("ComClassMethod", BindingFlags.InvokeMethod, null, comClassInstance, null);
Run Code Online (Sandbox Code Playgroud)
所以我想问一下,是否可以将"comClassInstance"转换为"ComClassType",以便能够以这种方式调用方法comClassInstance.ComClassMethod();