C#中的后期绑定 [英] Late Binding in C#

查看:92
本文介绍了C#中的后期绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个C#程序。我在一个返回

Object的COM对象上调用一个方法。我不知道对象的类型(反射只是说它是一个

__ComObject),但我知道应该有Controls属性。如何在不知道对象类型的情况下调用Controls属性?


在VB.NET中,如果Option Explicit关闭,你可以这样做只需编写

SomeObject.Controls。 VB.NET运行时将处理后期绑定,在这种情况下,

包括调用COM对象的IDispatch接口。我不知道如何在C#中做同样的事情。唯一的后期绑定示例

我可以找到C#假设您知道要调用的对象的类型。

I am writing an C# program. I call a method on a COM object that returns
Object. I don''t know the type of the object (and reflection just says its a
__ComObject), but I know there is supposed to be Controls property. How can
I call the Controls property without knowing the type of the object?

In VB.NET, you can just do this if Option Explicit is off by just writing
SomeObject.Controls. The VB.NET runtime will handle the late binding which,
in this case, includes calling the COM object''s IDispatch interface. I
don''t see how to do the same thing in C#. The only "late binding" examples
I can find for C# assume you know the type of the object you are calling.

推荐答案

您将需要调用方法。查看MSDN中的Invoke。


谢谢,


" Scott English" <无**** @ nospam.com>在留言中写道

新闻:%2 **************** @ TK2MSFTNGP11.phx.gbl ...
You will need to Invoke the method. Check out Invoke in MSDN.

Thanks,

"Scott English" <no****@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
我是写一个C#程序。我在一个返回
Object的COM对象上调用一个方法。我不知道对象的类型(并且反射只是说它的
a __ComObject),但我知道应该有Controls属性。
我怎么能在不知道对象类型的情况下调用Controls属性?

在VB.NET中,只要编写了Option Explicit,就可以执行此操作
SomeObject .Controls。 VB.NET运行时将处理后期绑定
,在这种情况下,包括调用COM对象的IDispatch接口。我没有看到如何在C#中做同样的事情。唯一的后期绑定我能为C#找到的
例子假设您知道要调用的对象的类型。
I am writing an C# program. I call a method on a COM object that returns
Object. I don''t know the type of the object (and reflection just says its a __ComObject), but I know there is supposed to be Controls property. How can I call the Controls property without knowing the type of the object?

In VB.NET, you can just do this if Option Explicit is off by just writing
SomeObject.Controls. The VB.NET runtime will handle the late binding which, in this case, includes calling the COM object''s IDispatch interface. I
don''t see how to do the same thing in C#. The only "late binding" examples I can find for C# assume you know the type of the object you are calling.



您是否引用了MethodBase .Invoke?要获取MethodBase对象,您必须首先知道方法所在对象的类型。我错过了什么吗?


" BuddyHome" <卜*** @ onlinehome.com>在消息中写道

新闻:Og ************* @ TK2MSFTNGP10.phx.gbl ...
Are you refering to MethodBase.Invoke? To get a MethodBase object, you must
first know the type of the object the method is on. Am I missing something?

"BuddyHome" <Bu***@onlinehome.com> wrote in message
news:Og*************@TK2MSFTNGP10.phx.gbl...
你需要调用方法。查看MSDN中的Invoke。

谢谢,

Scott English <无**** @ nospam.com>在消息中写道
新闻:%2 **************** @ TK2MSFTNGP11.phx.gbl ...
You will need to Invoke the method. Check out Invoke in MSDN.

Thanks,

"Scott English" <no****@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
我正在写一个C#程序。我在一个COM对象上调用一个方法,
返回Object。我不知道对象的类型(反射只是说
,它的
I am writing an C# program. I call a method on a COM object that returns Object. I don''t know the type of the object (and reflection just says its
一个
__ComObject),但我知道应该有控件属性。怎么
__ComObject), but I know there is supposed to be Controls property. How


我在不知道对象类型的情况下调用Controls属性?

在VB.NET中,你可以这样做只需
I call the Controls property without knowing the type of the object?

In VB.NET, you can just do this if Option Explicit is off by just



编写SomeObject.Controls即可关闭Option Explicit。 VB.NET运行时将处理后期绑定


writing SomeObject.Controls. The VB.NET runtime will handle the late binding


,在这种情况下,


which,

包括调用COM对象的IDispatch接口。我没有看到如何在C#中做同样的事情。唯一的后期绑定
in this case, includes calling the COM object''s IDispatch interface. I
don''t see how to do the same thing in C#. The only "late binding"


示例

我可以找到C#假设您知道对象的类型是
调用。
I can find for C# assume you know the type of the object you are calling.




抱歉Scott,


如果只是试图调用一个后期绑定的方法,那么看看这个文章。

http://groups.google.com/groups?hl=e...%3D10%26sa%3DN


" Scott English" <无**** @ nospam.com>在消息中写道

新闻:%2 **************** @ tk2msftngp13.phx.gbl ...
Sorry Scott,

If are just trying to call a method late bound then see this article.

http://groups.google.com/groups?hl=e...%3D10%26sa%3DN

"Scott English" <no****@nospam.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
你是引用MethodBase.Invoke?要获取MethodBase对象,
必须首先知道方法所在对象的类型。我错过了
的东西吗?
BuddyHome <卜*** @ onlinehome.com>在消息中写道
新闻:Og ************* @ TK2MSFTNGP10.phx.gbl ...
Are you refering to MethodBase.Invoke? To get a MethodBase object, you must first know the type of the object the method is on. Am I missing something?
"BuddyHome" <Bu***@onlinehome.com> wrote in message
news:Og*************@TK2MSFTNGP10.phx.gbl...
您需要调用该方法。查看MSDN中的Invoke。

谢谢,

Scott English <无**** @ nospam.com>在消息中写道
新闻:%2 **************** @ TK2MSFTNGP11.phx.gbl ...
You will need to Invoke the method. Check out Invoke in MSDN.

Thanks,

"Scott English" <no****@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
我正在写一个C#程序。我在一个返回Object的COM对象上调用一个方法。我不知道对象的类型(反射只是说它的
I am writing an C# program. I call a method on a COM object that returns Object. I don''t know the type of the object (and reflection just says its
一个
__ComObject),但我知道应该有Controls属性。
如何
__ComObject), but I know there is supposed to be Controls property. How
可以
我在不知道对象类型的情况下调用Controls属性?
在VB.NET中,只需按
I call the Controls property without knowing the type of the object?

In VB.NET, you can just do this if Option Explicit is off by just


编写SomeObject.Controls即可关闭Option Explicit。 VB.NET运行时将处理后期绑定


writing SomeObject.Controls. The VB.NET runtime will handle the late binding


,在这种情况下,


which,

包括调用COM对象的IDispatch接口。
in this case, includes calling the COM object''s IDispatch interface.


我不知道如何在C#中做同样的事情。唯一的后期绑定

I don''t see how to do the same thing in C#. The only "late binding"


示例

我可以找到C#,假设您知道对象的类型
I can find for C# assume you know the type of the object you are


打电话。


calling.





这篇关于C#中的后期绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆