如何昂贵是.NET反射? [英] How costly is .NET reflection?

查看:138
本文介绍了如何昂贵是.NET反射?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常听到多么糟糕的思考是使用。虽然我一般避免反光,很少发现情况就不可能解决我的问题,没有它,我不知道......

I constantly hear how bad reflection is to use. While I generally avoid reflection and rarely find situations where it is impossible to solve my problem without it, I was wondering...

对于那些谁在应用中使用的反射,让你测量的性能命中和,是不是真的那么差?

For those who have used reflection in applications, have you measured performance hits and, is it really so bad?

推荐答案

有。但是,这取决于你正在努力做的事情。

It is. But that depends on what you're trying to do.

我用反射动态加载程序集(插件),其性能惩罚是没有问题的,因为操作一些应用程序的启动过程中我做的。

I use reflection to dynamically load assemblies (plugins) and its performance "penalty" is not a problem, since the operation is something I do during startup of the application.

不过,如果你在里面反映了一系列的嵌套循环与每个反射的电话,我说你应该重新审视你的code:)

However, if you're reflecting inside a series of nested loops with reflection calls on each, I'd say you should revisit your code :)

有关一对夫妇的时候行动,反思是完全可以接受的,你不会注意到任何延迟或问题的。这是一个非常强大的机制,它甚至使用.NET,所以我不明白为什么你不应该给它一个尝试。

For "a couple of time" operations, reflection is perfectly acceptable and you won't notice any delay or problem with it. It's a very powerful mechanism and it is even used by .NET, so I don't see why you shouldn't give it a try.

这篇关于如何昂贵是.NET反射?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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