使用反射寻找方法 [英] Finding Methods using Reflection

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

问题描述

我正在编写一个应用程序并且正在为它创建一个插件接口




该应用程序需要找到 '插件'然后需要

才能找到所有可访问的方法。


相应的方法需要有一个相应的''用户

友好''名称。


例如:public void goForward(){...}需要有一个用户友好的

名称Go Forward


我正在考虑创建一个自定义对象的枚举(或者可能是
字符串数组),它们将存储两者方法名称(用于反射)

和相关的友好名称。


这看起来有点笨重。我是在正确的轨道还是在那里

更好的方法呢?

Hi, I am writing an application and am creating a plug-in interface
for it.

The application will need to ''find'' the plug-in''s and will then need
to find all accessible methods.

The corresponding methods will need to have a corresponding ''user
friendly'' name.

Eg: public void goForward() {...} will need to have a user friendly
name of "Go Forward"

I was thinking of creating an enumeration of custom objects (or maybe
string arrays ) that will store both the method name (for reflection)
and the associated friendly name.

This however seems a bit clunky. Am I on the right track or is there
any better way to do this?

推荐答案

Ian,

插件架构背后的想法是你有一个接口,从所有插件必须派生的

,然后实例化。您的通话程序

将知道可用的方法,以及如何使用它们。


这样一来,程序需要知道的是插件(如果您只是通过插件文件夹中的.DLL文件枚举,那么很简单),然后调用

界面上的方法,并让插件执行此操作是的。


这有意义吗?


如果你愿意,我有一些你可以看的代码.. 。
http://www.dunesand.com/blog /developer/developer.htm


如果您需要更多帮助,请告诉我。


稍后。

Dan。


" Ian" <他****** @ hotmail.com>在消息中写道

news:e7 ************************** @ posting.google.c om ...

您好,我正在编写一个应用程序并正在创建一个插件接口




应用程序需要找到插件'然后需要

才能找到所有可访问的方法。


相应的方法需要有相应的''用户

友好''名称。


例如:public void goForward(){...}需要有一个用户友好

名称前进


我正在考虑创建自定义对象的枚举(或者可能是
字符串数组)这将存储方法名称(用于反射)

和相关的友好名称。


这看起来有点笨重。我是在正确的轨道上还是在那里

更好的方法吗?
Ian,

The idea behind plug-in architecture is that you have one interface, from
which all plugins must derive, and then instantiate. Your calling program
will then know what methods are available, and what to do with them.

This way all a program needs to know is the location of the plugin (easy if
you just enumerate through the .DLL files in a plugin folder say), then call
the methods on the interface, and let the plugin do it''s thing.

Does that make sense?

I''ve got some code you can look at if you like...
http://www.dunesand.com/blog/developer/developer.htm

let me know if you need any more help with that.

Later.
Dan.

"Ian" <he******@hotmail.com> wrote in message
news:e7**************************@posting.google.c om...
Hi, I am writing an application and am creating a plug-in interface
for it.

The application will need to ''find'' the plug-in''s and will then need
to find all accessible methods.

The corresponding methods will need to have a corresponding ''user
friendly'' name.

Eg: public void goForward() {...} will need to have a user friendly
name of "Go Forward"

I was thinking of creating an enumeration of custom objects (or maybe
string arrays ) that will store both the method name (for reflection)
and the associated friendly name.

This however seems a bit clunky. Am I on the right track or is there
any better way to do this?


如果你的界面中有一个功能有一个通用声音名称,

例如DoWork()

您可以创建一个可用于提供更有意义的
名称的属性。

此属性的值可以是在运行时确定。


[FriendlyDescription(此操作会产生模糊温暖的感觉,而你需要等待b $ b)

public void DoWork()

{

}

Chris


" Daniel Bass" <我真的@厌恶垃圾邮件>在消息中写道

新闻:O4 ************** @ TK2MSFTNGP12.phx.gbl ...
If you have a function in your interface that has a generic sounding name,
e.g. DoWork()
You could create an attribute that can be used to supply a more meaningful
name.
The value of this attribute can be determined at runtime.

[FriendlyDescription("This operation creates a fuzzy warm feeling while you
wait")]
public void DoWork()
{
}
Chris

"Daniel Bass" <I''m really @ sick of spam> wrote in message
news:O4**************@TK2MSFTNGP12.phx.gbl...
Ian,
插件架构背后的想法是你有一个接口,所有插件必须从中派生出来,然后实例化。您的调用程序
将知道可用的方法以及如何使用它们。

所有程序需要知道的是插件的位置(简单
)如果你只是枚举一个插件文件夹中的.DLL文件说),那么
调用界面上的方法,然后让插件做它的事情。

这样做感觉?

如果你愿意,我有一些你可以看的代码...
http://www.dunesand.com/blog/developer/developer.htm

如果您需要,请告诉我对此有任何帮助。

后来。
Dan。

Ian <他****** @ hotmail.com>在消息中写道
新闻:e7 ************************** @ posting.google.c om ...
我正在编写一个应用程序,并为它创建一个插件接口。

应用程序需要找到插件,然后才会需要
找到所有可访问的方法。

相应的方法需要有一个相应的''用户友好''名称。

例如: public void goForward(){...}需要有一个用户友好的名称Go Forward

我想创建一个自定义对象的枚举(或者可能
字符串数组)将存储方法名称(用于反射)
和相关的友好名称。

这看起来有点笨重。我是在正确的轨道上还是在那里
有更好的方法吗?
Ian,

The idea behind plug-in architecture is that you have one interface, from
which all plugins must derive, and then instantiate. Your calling program
will then know what methods are available, and what to do with them.

This way all a program needs to know is the location of the plugin (easy if you just enumerate through the .DLL files in a plugin folder say), then call the methods on the interface, and let the plugin do it''s thing.

Does that make sense?

I''ve got some code you can look at if you like...
http://www.dunesand.com/blog/developer/developer.htm

let me know if you need any more help with that.

Later.
Dan.

"Ian" <he******@hotmail.com> wrote in message
news:e7**************************@posting.google.c om...
Hi, I am writing an application and am creating a plug-in interface
for it.

The application will need to ''find'' the plug-in''s and will then need
to find all accessible methods.

The corresponding methods will need to have a corresponding ''user
friendly'' name.

Eg: public void goForward() {...} will need to have a user friendly
name of "Go Forward"

I was thinking of creating an enumeration of custom objects (or maybe
string arrays ) that will store both the method name (for reflection)
and the associated friendly name.

This however seems a bit clunky. Am I on the right track or is there
any better way to do this?



" Daniel Bass" <我真的@厌恶垃圾邮件>在消息新闻中写道:< O4 ************** @ TK2MSFTNGP12.phx.gbl> ...
"Daniel Bass" <I''m really @ sick of spam> wrote in message news:<O4**************@TK2MSFTNGP12.phx.gbl>...
Ian,

插件架构背后的想法是你有一个接口,
所有插件必须派生,然后实例化。您的调用程序
将知道可用的方法以及如何使用它们。

这样一来,程序需要知道的是插件的位置(如果
你只需枚举一个插件文件夹中的.DLL文件,然后调用接口上的方法,让插件做它的事情。

这样做感觉?

如果你愿意,我有一些你可以看的代码...
http://www.dunesand.com/blog/developer/developer.htm

如果您需要,请告诉我还有更多的帮助。

后来。
Dan。
Ian,

The idea behind plug-in architecture is that you have one interface, from
which all plugins must derive, and then instantiate. Your calling program
will then know what methods are available, and what to do with them.

This way all a program needs to know is the location of the plugin (easy if
you just enumerate through the .DLL files in a plugin folder say), then call
the methods on the interface, and let the plugin do it''s thing.

Does that make sense?

I''ve got some code you can look at if you like...
http://www.dunesand.com/blog/developer/developer.htm

let me know if you need any more help with that.

Later.
Dan.




感谢Dan,我给了他一些想法,但是很快就把它解雇了

因为我不知道第三方开发者会使用什么功能

- 他们需要这种灵活性。

看看你的代码然而给了我一些想法,它可能实际上是
通往低头的道路。


Ian。



Thanks for that Dan, I gave that some thought, but soon dismissed it
as I won''t know what functions the 3rd party developer is going to use
- and they need that flexibility.

Looking at your code however has given me a couple of ideas, it may
actually be the path to head down.

Ian.


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

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