当你使用反射?模式/反模式 [英] When do you use reflection? Patterns/anti-patterns

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

问题描述

据我了解反射API(在C#),但我不知道什么情况下,我会使用它。有哪些模式? - 反模式使用反射

I understand the reflection API (in c#) but I am not sure in what situation would I use it. What are some patterns - anti-patterns for using reflection?

推荐答案

我已经使用在C#中的反思的东西是工厂模式的唯一的地方,在那里我创建对象(在我的情况下,网络监听器)的基础上配置文件信息。配置文件中提供的组件的位置,在其中的种类的名称,以及所需要的任何额外参数。工厂选择这个东西了,创造了听众基于这一点。

The only place I've used the Reflection stuff in C# was in factory patterns, where I'm creating objects (in my case, network listeners) based on configuration file information. The configuration file supplied the location of the assemblies, the name of the types within them, and any additional arguments needed. The factory picked this stuff up and created the listeners based on that.

这篇关于当你使用反射?模式/反模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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