Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我弄完了
fake1 = A.Fake<MyType>()
然后我想在假货上使用“反射”来将依赖项与我的依赖项容器注册为 MyType。但是,我无法弄清楚如何获得底层的伪造类型。任何指针?
这是我最终得到的代码。
var builder = new ContainerBuilder(); foreach (var obj in fakes) { Type fakedType = obj.GetType().BaseType; builder.RegisterInstance(obj).As(fakedType); }
请注意,它假设您正在对基类伪造而不是接口伪造进行虚拟方法,因为目前这对我来说是正确的。:)
您可以通过更多反射轻松扩展它,以将实例注册为其所有继承的接口......