How to create a new object instance from a Type

后端 未结 12 1750
孤城傲影
孤城傲影 2020-11-22 03:26

One may not always know the Type of an object at compile-time, but may need to create an instance of the Type.

How do you get a new objec

12条回答
  •  长发绾君心
    2020-11-22 03:59

    Given this problem the Activator will work when there is a parameterless ctor. If this is a constraint consider using

    System.Runtime.Serialization.FormatterServices.GetSafeUninitializedObject()
    

提交回复
热议问题