简体   繁体   中英

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. 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)?

It sounds like you're asking the difference between early binding (static) and late binding (dynamic). C# supports both.

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.

To use late binding you can use either reflection (messy) or the dynamic keyword to bind the method calls at run-time.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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