何时或为何使用反射 [英] When or why to use reflection

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

问题描述



我正在为初学者教C#.课程的一部分涉及反思.
问题在于我很难找到简单何时/应该使用反射代替其他解决方案的示例.

如果有人可以举一个或多个示例,其中反射的使用将是有益的,那对我来说将是很大的帮助.

在此先感谢.

Hi,

I''m teaching C# for beginners. One part of the course concerns Reflection.
The problems is that I have difficulties to find an simple example of when reflection could/should be used instead of a other solution.

If anyone could give one or more examples, where the use of reflection would be benificial, it would be a great help to me.

Thanks in advance.

推荐答案

我在以下情况下使用反射:

1)我使用的是某些插件模式,在应用程序启动时您会在目录中扫描程序集,并加载实现某些接口的类的实例
2)我正在使用自定义属性

还有一些与工具相关的特定场景,例如开发IDE工具时,用于类/对象探索的工具,反汇编/研究类型的工具等.

希望对您有所帮助.

干杯.
I use reflection when:

1) I am using certain plug-in patterns, where you scan a directory for assemblies at app-start up and load instances of classes that implement certain interfaces
2) I am working with custom attributes

There are also specific tools-related scenarios, such as when developing IDE tools, tools for class/object exploration, disassembly/research type tools etc.

Hope this helps some.

Cheers.


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

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