小编Mic*_*ous的帖子

System .__ ComObject的动态转换

是否可以将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();

c# com casting dynamic type-conversion

4
推荐指数
2
解决办法
2105
查看次数

标签 统计

c# ×1

casting ×1

com ×1

dynamic ×1

type-conversion ×1