反射,基类私有属性等 [英] reflection, base class private properties, etc.

查看:64
本文介绍了反射,基类私有属性等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个老问题,到目前为止我无法解决。现在我在该组中找到了一个帖子

给了我一个想法,但我无法完全理解它。

问题是:我正在尝试使用COM

环境中的Windows.Forms.UserControl,即我想在COM主机中托管该控件。到目前为止,所以

好​​,我可以托管它,但是我无法从

控件到达父COM对象(Parent属性为null :()。 />
我已经停止了调试器中的控件,我在监视窗口找到了

一些属性,比如ActiveXInstance

{System.Windows.Forms.Control .ActiveXImpl}

问题是它们是基类私有的,所以我无法访问

它们。


现在的问题是:是否有可能以某种方式以编程方式访问这些基本属性

。我发现了一个帖子提到了一些关于

反射(无论那个意思)。我可以使用访问这些

属性的反映?


任何帮助都将受到高度赞赏。


谢谢

Sunny

Hi,
I have an old problem which I couldn''t solve so far. Now I have found a post
in that group that gave me an idea, but I can not fully understand it.
The problem is: I''m trying to use a Windows.Forms.UserControl in a COM
environment, i.e. I want to host that control in a COM host. So far, so
good, I can host it, but I can not reach the parent COM object from the
control (Parent property is null :( ).
I have stopped the control in the debugger and I found in the watch window
some properties, like ActiveXInstance
{System.Windows.Forms.Control.ActiveXImpl}
The problem is that they are private to the base class, so I can not access
them.

Now the question: is it possible somehow to access these base properties
programmatically. I have found a post which mentions something about
reflection (whatever that mean). Can I use a reflection to access these
properties?

Any help will be highly appreciated.

Thanks
Sunny

推荐答案

嗨Sunny,

我认为是的,它可以访问一个类的私有属性

使用反射,我还没有测试过,但我也看到了尼古拉斯的帖子

,直到现在他说的都是真的;),事情是(也在

中说明了post)你打算用它做什么?它;私人财产和

你不知道它是如何使用的或它意味着什么。


干杯,


-

Ignacio Machin,

ignacio.machin AT dot.state.fl.us

佛罗里达州运输部


晴天 <苏****** @ icebergwireless.com>在留言中写道

news:uO ************* @ tk2msftngp13.phx.gbl ...
Hi Sunny,
I think that yes, it''s possible to access the private properties of a class
using reflection, I haven''t tested it but I also saw the post of Nicholas
and until now all that he said is true ;) , the thing is ( also stated in
the post ) what are you planning to do with it? it;s a private property and
you have no idea of how it''s used or what it means.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Sunny" <su******@icebergwireless.com> wrote in message
news:uO*************@tk2msftngp13.phx.gbl...

我有一个老问题,到目前为止我无法解决。现在我在该组中发现了一个
的帖子给了我一个想法,但我无法完全理解它。
问题是:我正在尝试使用Windows.Forms.UserControl COM
环境,即我想在COM主机中托管该控件。到目前为止,所以
好,我可以托管它,但是我无法从
控件到达父COM对象(Parent属性为null :()。
我已经停止了控件调试器和我在监视窗口中找到了一些属性,比如ActiveXInstance
{System.Windows.Forms.Control.ActiveXImpl}
问题是它们是基类私有的,所以我不能
访问它们。

现在问题:是否有可能以某种方式以编程方式访问这些基本属性。我找到了一个帖子提到了一些关于
的内容反射(无论是什么意思)。我可以使用反射来访问这些
属性吗?

任何帮助都将受到高度赞赏。

谢谢
Sunny
Hi,
I have an old problem which I couldn''t solve so far. Now I have found a post in that group that gave me an idea, but I can not fully understand it.
The problem is: I''m trying to use a Windows.Forms.UserControl in a COM
environment, i.e. I want to host that control in a COM host. So far, so
good, I can host it, but I can not reach the parent COM object from the
control (Parent property is null :( ).
I have stopped the control in the debugger and I found in the watch window
some properties, like ActiveXInstance
{System.Windows.Forms.Control.ActiveXImpl}
The problem is that they are private to the base class, so I can not access them.

Now the question: is it possible somehow to access these base properties
programmatically. I have found a post which mentions something about
reflection (whatever that mean). Can I use a reflection to access these
properties?

Any help will be highly appreciated.

Thanks
Sunny



似乎我必须猜测要获得什么属性,所以我会玩

所有这些,但总是发生组合COM / .Net / Outlook :)

问题是,我已经读过了我的反思文档,我仍然

不知道从哪里开始以及如何访问这些私人成员:(

所以任何例子都会有所帮助。


Sunny


" Ignacio Machin" < ignacio.machin AT dot.state.fl.us>在消息中写道

news:ul **************** @ TK2MSFTNGP12.phx.gbl ...
Hi, it seems that I have to guess what property to get, so I''ll play with
all of them, but that happen always with combination COM/.Net/Outlook :)
The problem is, that I have read some of docs for reflection, and I still
have no idea where to start and how to access these private members :(
So any example will be helpful.

Sunny

"Ignacio Machin" <ignacio.machin AT dot.state.fl.us> wrote in message
news:ul****************@TK2MSFTNGP12.phx.gbl...
嗨Sunny,

我认为是的,可以使用反射访问
类的私有属性,我还没有测试它但是我也看到了Nicholas的帖子直到现在他说的都是真的;),事情是(在帖子中也说明了)你打算用它做什么?它;私人财产
,你不知道它是如何使用的或它意味着什么。

干杯,

-
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
佛罗里达州交通局

Sunny <苏****** @ icebergwireless.com>在消息中写道
新闻:uO ************* @ tk2msftngp13.phx.gbl ...
Hi Sunny,
I think that yes, it''s possible to access the private properties of a class using reflection, I haven''t tested it but I also saw the post of Nicholas
and until now all that he said is true ;) , the thing is ( also stated in
the post ) what are you planning to do with it? it;s a private property and you have no idea of how it''s used or what it means.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Sunny" <su******@icebergwireless.com> wrote in message
news:uO*************@tk2msftngp13.phx.gbl...

我老了到目前为止我无法解决的问题。现在我在那个组中发现
Hi,
I have an old problem which I couldn''t solve so far. Now I have found a

帖子
给了我一个想法,但我无法完全理解它。
问题是:我''我试图在COM
环境中使用Windows.Forms.UserControl,即我想在COM主机中托管该控件。到目前为止,所以
好,我可以托管它,但是我无法从
控件到达父COM对象(Parent属性为null :()。
我已经停止了控件调试器和我在watch
窗口中找到了一些属性,比如ActiveXInstance
{System.Windows.Forms.Control.ActiveXImpl}
问题是它们是基类私有的,所以我不能
in that group that gave me an idea, but I can not fully understand it.
The problem is: I''m trying to use a Windows.Forms.UserControl in a COM
environment, i.e. I want to host that control in a COM host. So far, so
good, I can host it, but I can not reach the parent COM object from the
control (Parent property is null :( ).
I have stopped the control in the debugger and I found in the watch window some properties, like ActiveXInstance
{System.Windows.Forms.Control.ActiveXImpl}
The problem is that they are private to the base class, so I can not


访问

他们。

现在问题:是否有可能以某种方式以编程方式访问这些基本属性。我我发现了一个帖子提到了一些关于
反射的内容(不管是什么意思)。我可以使用反射来访问这些
属性吗?

任何帮助都将受到高度赞赏。 />
谢谢
Sunny
them.

Now the question: is it possible somehow to access these base properties
programmatically. I have found a post which mentions something about
reflection (whatever that mean). Can I use a reflection to access these
properties?

Any help will be highly appreciated.

Thanks
Sunny




这是一个示例代码(在VB但不应该难以翻译

it)我曾经获得UserMode属性:


Dim strAssembly As String

strAssembly =

Type.GetType(" System.Object")。Assembly.CodeBase.Re place(" mscorlib.dll",& br />
" System.Windows.Forms.dll")

strAssembly = strAssembly.Replace(" file:///" ;, String.Empty)

strAssembly = Reflection.AssemblyName.GetAssemblyName(strAssembl y).FullName

Dim unmt As Type = _

Type.GetType(Reflection.Assembly.CreateQualifiedNa me( strAssembly,

" System.Windows.Forms.UnsafeNativeMethods"))

Dim ioot As Type = unmt.GetNestedType(" IOleObject")

Dim mi As Reflection.MethodInfo = ioot.GetMethod(" GetClientSite")

Dim site As Object = mi.Invoke(Me,Nothing)

如果site is Is什么然后返回-1


''我们由COM容器托管


Dim dsite As IDispatch = site


''在这种情况下,所有未初始化的参数都可以正常工作

Dim id As Guid

Dim params As DISPPARAMS

Dim lcid As System.UInt32

Dim wFlags As System。 UInt16 = System.UInt16.Parse(2.ToString())

昏暗的结果作为对象

dsite.Invoke(-709,id,lcid,wFlags,params,result ,没什么,没什么)


如果结果那么

返回1

否则

返回0

结束如果


这应该会让你知道如何做你想要的。 IIRC IOleClientSite

有我认为你需要的方法GetContainer()(不是父COM

对象)。顺便说一下你可以在System.Windows.Forms.dll上使用ildasm来让自己熟悉内部类和实现。


谢谢,

v


" Sunny" <苏****** @ icebergwireless.com>在消息中写道

新闻:ui ************** @ tk2msftngp13.phx.gbl ...
Here is a sample code (in VB but it shouldn''t not be difficult to translate
it) I used to get UserMode property:

Dim strAssembly As String
strAssembly =
Type.GetType("System.Object").Assembly.CodeBase.Re place("mscorlib.dll",
"System.Windows.Forms.dll")
strAssembly = strAssembly.Replace("file:///", String.Empty)
strAssembly = Reflection.AssemblyName.GetAssemblyName(strAssembl y).FullName
Dim unmt As Type = _
Type.GetType(Reflection.Assembly.CreateQualifiedNa me(strAssembly,
"System.Windows.Forms.UnsafeNativeMethods"))
Dim ioot As Type = unmt.GetNestedType("IOleObject")
Dim mi As Reflection.MethodInfo = ioot.GetMethod("GetClientSite")
Dim site As Object = mi.Invoke(Me, Nothing)
If site Is Nothing Then Return -1

'' We are hosted by a COM container

Dim dsite As IDispatch = site

'' All the uninitialized arguments work fine in this case
Dim id As Guid
Dim params As DISPPARAMS
Dim lcid As System.UInt32
Dim wFlags As System.UInt16 = System.UInt16.Parse(2.ToString())
Dim result As Object
dsite.Invoke(-709, id, lcid, wFlags, params, result, Nothing, Nothing)

If result Then
Return 1
Else
Return 0
End If

That should give you an idea how to do what you want. IIRC IOleClientSite
has method GetContainer() which I think you need (not the parent COM
object). BTW You can use ildasm on System.Windows.Forms.dll to make yourself
familiar with the internal classes and implementations.

thanks,
v

"Sunny" <su******@icebergwireless.com> wrote in message
news:ui**************@tk2msftngp13.phx.gbl...
似乎我必须猜测要获得什么属性,所以我会玩
所有这些,但这种情况总是发生在组合COM / .Net / Outlook :)
问题是,我已阅读一些反思的文档,我仍然不知道从哪里开始以及如何访问这些私人成员:(
所以任何一个例子都会有所帮助。

Sunny

Ignacio Machin< ignacio.machin AT dot.state.fl.us>在消息中写道
新闻:ul *************** *@TK2MSFTNGP12.phx.gbl ...
Hi, it seems that I have to guess what property to get, so I''ll play with
all of them, but that happen always with combination COM/.Net/Outlook :)
The problem is, that I have read some of docs for reflection, and I still
have no idea where to start and how to access these private members :(
So any example will be helpful.

Sunny

"Ignacio Machin" <ignacio.machin AT dot.state.fl.us> wrote in message
news:ul****************@TK2MSFTNGP12.phx.gbl...
嗨Sunny,

我认为是的,它可以访问
Hi Sunny,
I think that yes, it''s possible to access the private properties of a

的私有属性
class


class

使用反射,我还没有测试过,但我也看到了
的帖子Nicholas
using reflection, I haven''t tested it but I also saw the post of Nicholas
到现在为止他说的只是tr呃;),事情是(在帖子中也说明了
)你打算用它做什么?它;一个私有财产
and until now all that he said is true ;) , the thing is ( also stated in the post ) what are you planning to do with it? it;s a private property


你不知道它是如何被使用或它意味着什么。

干杯,

-
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
佛罗里达州交通局

Sunny <苏****** @ icebergwireless.com>在消息中写道
新闻:uO ************* @ tk2msftngp13.phx.gbl ...
you have no idea of how it''s used or what it means.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Sunny" <su******@icebergwireless.com> wrote in message
news:uO*************@tk2msftngp13.phx.gbl...

我老了到目前为止我无法解决的问题。现在我发现
a
Hi,
I have an old problem which I couldn''t solve so far. Now I have found a
发布
的那个组给了我一个想法,但我无法完全理解它。
问题是:我正在尝试在COM环境中使用Windows.Forms.UserControl,即我想在COM主机中托管该控件。到目前为止,
in that group that gave me an idea, but I can not fully understand it.
The problem is: I''m trying to use a Windows.Forms.UserControl in a COM
environment, i.e. I want to host that control in a COM host. So far,



这么好,我可以托管它,但我无法从
到达父COM对象的控件(Parent属性)是null :()。
我已经停止了调试器中的控件,我在watch


so good, I can host it, but I can not reach the parent COM object from the control (Parent property is null :( ).
I have stopped the control in the debugger and I found in the watch


窗口中找到了一些属性,比如ActiveXInstance
{System.Windows .Forms.Control.ActiveXImpl}
问题是它们是基类的私有,所以我不能


window some properties, like ActiveXInstance
{System.Windows.Forms.Control.ActiveXImpl}
The problem is that they are private to the base class, so I can not


访问

它们。

现在的问题是:是否有可能以某种方式以编程方式访问这些基本的
属性。我找到了一个帖子,其中提到了关于
反射的内容(无论是什么意思)。我可以使用反射来访问
这些房产?

任何帮助都将受到高度赞赏。

谢谢
Sunny
them.

Now the question: is it possible somehow to access these base properties programmatically. I have found a post which mentions something about
reflection (whatever that mean). Can I use a reflection to access these properties?

Any help will be highly appreciated.

Thanks
Sunny





这篇关于反射,基类私有属性等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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