提高性能思考,我应该考虑什么替代品替代品、性能

由网友(我长居炼狱只为你百岁无忧)分享简介:我需要动态上的对象一堆或属性设置值,称之为传输对象。将有将被创建,并在再寄一次短的空间设置其属性要避免使用反射这些传输对象相当数量的,还有可选择性?如果是的话有没有示例实现,我可以看看?I need to dynamically set values on a bunch or properties on an ob...

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

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.

阅读全文

相关推荐

最新文章