How to pass ctor args in Activator.CreateInstance or use IL?

后端 未结 8 1757
野的像风
野的像风 2020-12-07 16:06

I need a performance enhanced Activator.CreateInstance() and came across this article by Miron Abramson that uses a factory to create the instance in IL and then cache it. (

8条回答
  •  醉话见心
    2020-12-07 16:54

    Has your profiler shown you that a large amount of time is spent in Activator.CreateInstance() (and not any constructor called by it) if you don't use the simple approach. If that is not the case, just use Activator.CreateInstance. (There seems to not be a generic CreateInstance() method with ctor arguments, but there is a non-generic one).

提交回复
热议问题