提高性能思考,我应该考虑什么替代品 [英] Improving performance reflection , what alternatives should I consider

查看:204
本文介绍了提高性能思考,我应该考虑什么替代品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要动态上的对象一堆或属性设置值,称之为传输对象。将有将被创建,并在再寄一次短的空间设置其属性要避免使用反射这些传输对象相当数量的,还有可选择性?如果是的话有没有示例实现,我可以看看?

I need to dynamically set values on a bunch or properties on an object , call it a transmission object. There will be a fair number of these transmission objects that will be created and have its properties set in a short space of time.I want to avoid the use of reflection, are there alternativ? If so are there sample implementations I could look at?

感谢

推荐答案

使用的 Delegate.CreateDelegate 把一个的MethodInfo 成一个强类型的代表。这可以提高性能的大型的。我对此有一个博客文章样品code。请注意,这只会帮助,如果你需要设置相同的属性多次 - 基本上就意味着有很多的类型检查完成的一次的当您创建的委托,而不是每次调用

Use Delegate.CreateDelegate to turn a MethodInfo into a strongly-typed delegate. This can improve performance massively. I have a blog post about this with sample code. Note that this is only going to help if you need to set the same properties multiple times - basically it means that a lot of the type checking is done once when you create the delegate, rather than on every invocation.

马克Gravell有 HyperPropertyDescriptor 的项目,该项目实现了更高的性能,但引入了一个额外的依赖。

Marc Gravell has a HyperPropertyDescriptor project which achieves even better performance, but introduces an extra dependency.

这篇关于提高性能思考,我应该考虑什么替代品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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