【发布时间】:2016-12-23 12:10:07
【问题描述】:
Autofixture 能够使用Fixture.Create<T>() 方法创建任何类型的实例。
但我需要在运行时创建一个类型。默认情况下,非泛型 Fixture.Create() 需要一个“种子”,这不是我想要的。
如何在运行时创建给定类型的实例?
【问题讨论】:
标签: autofixture
Autofixture 能够使用Fixture.Create<T>() 方法创建任何类型的实例。
但我需要在运行时创建一个类型。默认情况下,非泛型 Fixture.Create() 需要一个“种子”,这不是我想要的。
如何在运行时创建给定类型的实例?
【问题讨论】:
标签: autofixture
通过查看我制定的 Autofixture 源代码,我可以这样做:
var fixture = new Fixture();
Type type = ... // My runtime type
var instance = fixture.Create(type, new SpecimenContext(fixture));
不确定这是否是最好的方法,但它似乎有效。
【讨论】: