Activator.CreateInstance - How to create instances of classes that have parameterized constructors

后端 未结 5 1752
野性不改
野性不改 2020-12-24 12:21

I have read a few bits and bobs online about this topic but found none that work for me. What I am trying to do is create a class of a runtime Type.

I use Acti

5条回答
  •  抹茶落季
    2020-12-24 12:43

    As an alternative to Activator.CreateInstance, FastObjectFactory in the linked url preforms better than Activator (as of .NET 4.0 and significantly better than .NET 3.5. No tests/stats done with .NET 4.5). See StackOverflow post for stats, info and code. Note that some modifications may need to be done based upon the number of ctor params. The code provided only allows 1 ctor param but can be modified to have more than 1. See comments in code.

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

提交回复
热议问题