反思与动态方法 [英] Reflection and Dynamic Methods

查看:85
本文介绍了反思与动态方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的情况是我有一个对象名称作为字符串,而一个方法是

一个字符串。我需要构建一个包含

信息的点击处理程序。这就是我到目前为止所提出的......以及我收到的错误信息
...


汇编汇编= Assembly.GetExecutingAssembly() ;

string currentNamespace =

Assembly.GetExecutingAssembly()。GetTypes()[0] .Namespace;

Type type = assem.GetType( currentNamespace +"。" + m_FormName,true,true);

MethodInfo methinf = type.GetMethod(MethodCall);

m_ButtonControl.Click + = new CommandEventHandler(methinf );


错误1''methinf''是一个''变量''但是用'''方法''


谢谢,

Ron

解决方案

" Ron" < rs ******** @ yahoo.comwrote:


m_ButtonControl.Click + = new CommandEventHandler(methinf);

错误1''methinf''是''变量''但是像''方法'一样使用'



我不确定CommandEventHandler是什么,但这种方式适用于我

Windows窗体:


MethodInfo methinf = type.GetMethod(" NameOfMethod");

theButton.Click + = new EventHandler(MethodCall);


Eq。


哦,忽略上一篇文章。我犯了一个错误。


Eq。


4月16日,1:35 * pm,Paul E Collins < find_my_real_addr ... @ CL4.org>

写道:


" Ron" < rs_herh ... @ yahoo.comwrote:


m_ButtonControl.Click + = new CommandEventHandler(methinf);

错误1'' methinf''是''变量''但是像''方法'一样使用'



我不确定CommandEventHandler是什么,但这种方式有效对我来说

Windows窗体:



它是一个委托,用于web控件中的onCommand事件


I have a situation where I have an object name as a string, and a method as
a string. I need to construct a click handler with those two bits of
information. This is what I came up with so far... and the error message I
am receiving...

Assembly assem = Assembly.GetExecutingAssembly();
string currentNamespace =
Assembly.GetExecutingAssembly().GetTypes()[0].Namespace;
Type type = assem.GetType(currentNamespace + "." + m_FormName, true, true);
MethodInfo methinf = type.GetMethod(MethodCall);
m_ButtonControl.Click += new CommandEventHandler(methinf);

Error 1 ''methinf'' is a ''variable'' but is used like a ''method''

Thanks,
Ron

解决方案

"Ron" <rs********@yahoo.comwrote:

m_ButtonControl.Click += new CommandEventHandler(methinf);
Error 1 ''methinf'' is a ''variable'' but is used like a ''method''

I''m not sure what CommandEventHandler is, but this way works for me in
Windows Forms:

MethodInfo methinf = type.GetMethod("NameOfMethod");
theButton.Click += new EventHandler(MethodCall);

Eq.


Oh, ignore the previous post. I made a mistake.

Eq.


On Apr 16, 1:35*pm, "Paul E Collins" <find_my_real_addr...@CL4.org>
wrote:

"Ron" <rs_herh...@yahoo.comwrote:

m_ButtonControl.Click += new CommandEventHandler(methinf);
Error 1 ''methinf'' is a ''variable'' but is used like a ''method''


I''m not sure what CommandEventHandler is, but this way works for me in
Windows Forms:

It''s a delegate, to be used in the onCommand event in web controls


这篇关于反思与动态方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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