How to Pass Parameters to Activator.CreateInstance()

前端 未结 5 540
名媛妹妹
名媛妹妹 2020-11-28 04:42

I want to create an instance of a type that I specify in a generic method that I have. This type has a number of overloaded constructors. I\'d like to be able to pass argume

5条回答
  •  感情败类
    2020-11-28 05:30

    Keep in mind though that passing arguments on Activator.CreateInstance has a significant performance difference versus parameterless creation.

    There are better alternatives for dynamically creating objects using pre compiled lambda. Of course always performance is subjective and it clearly depends on each case if it's worth it or not.

    Details about the issue on this article.

    Graph is taken from the article and represents time taken in ms per 1000 calls.

提交回复
热议问题