我正在维护别人的代码,他们在一个方法中有这个部分:
object ReportCriteriaInstance =
Activator.CreateInstance(
typeof(MyCompany.Utils.ReportStructure.ReportSearchCriteria));
//ReportCriteria is passed in as a method parameter
ReportCriteriaInstance = ReportCriteria;
我不知道为什么他们在ReportCriteriaInstace
用CreateInstance()
.
除此之外,因为我们将已知类型传递给CreateInstance
( MyCompany.Utils.ReportStructure.ReportSearchCriteria
),是否有任何理由不使用 new() 代替?我没有得到一些默认的无参数构造函数的原因可能是什么?