我有一个类,它将可空int作为参数。
public class Test
{
public Test(int? p)
{
// ......
}
// ......
}如何使用统一(传递null作为参数)来解析它?
myContainer.RegisterType<Test>(new InjectionConstructor(10));这可以作为值传递10,但是如果我传递null,它会抛出异常。
发布于 2013-09-02 10:04:33
编辑使用泛型:
尝试使用InjectionParameter代替:
container.RegisterType<Test>(new InjectionConstructor(new InjectionParameter<int?>(null)));发布于 2013-09-02 10:07:19
使用正确类型的InjectionParameter<T>,即
container.RegisterType<Test>(new InjectionConstructor(new InjectionParameter<int?>(null)));这已经在中进行了测试。
https://stackoverflow.com/questions/18570168
复制相似问题