简体   繁体   English

COM 对象是动态的还是静态的

[英]Are COM objects dynamic or static

I am trying to make a sort of proxy, and I am wondering whether COM methods and properties are static or dynamic.我正在尝试创建一种代理,我想知道 COM 方法和属性是静态的还是动态的。 In other words, does .NET call the com object and tell it which method it wants executed, and then lets the com object pretend it has executed it (the way DynamicObject lets you do in .NET, just return true for TryInvokeMember without doing anything), or does .NET actually go and call the COM method directly (static)?换句话说,.NET 是否调用 com 对象并告诉它它想要执行哪个方法,然后让 com 对象假装它已经执行了它(DynamicObject 让你在 .NET 中做的方式,只需为 TryInvokeMember 返回 true 而不做任何事情),还是 .NET 实际上会直接调用 COM 方法(静态)?

It sounds like you're asking the difference between early binding (static) and late binding (dynamic).听起来您在问早期绑定(静态)和后期绑定(动态)之间的区别。 C# supports both. C# 支持两者。

Early binding requires you create an Interop assembly using a tool like TlbImp.exe to generate a proxy to the COM object, which calls the interface methods directly.早期绑定要求您使用TlbImp.exe 等工具创建 Interop 程序集以生成 COM 对象的代理,该代理直接调用接口方法。

To use late binding you can use either reflection (messy) or the dynamic keyword to bind the method calls at run-time.要使用后期绑定,您可以使用反射(混乱)或dynamic关键字在运行时绑定方法调用。

However, the COM object will not "pretend" it executed a method you ask for - if the method does not exist, you will get a run-time exception.但是,COM 对象不会“假装”它执行了您请求的方法——如果该方法不存在,您将收到运行时异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM