public InjectableConstructor(ConstructorInfo constructor, IInjectableParameter[] parameters) : base(constructor) { this.parameters = parameters; wrapper = constructor.CreateWrapper(); arguments = new object[parameters.Length]; }
private static void AssertNullCheckForEveryPossibleArgumentOf(IConstraintsViolations violations, IConstructorWrapper constructor, FallbackTypeGenerator fallbackTypeGenerator) { for (int i = 0; i < constructor.GetParametersCount(); ++i) { var parameters = constructor.GenerateAnyParameterValues(Any.Instance); if (SmartType.ForTypeOf(parameters[i]).CanBeAssignedNullValue()) { parameters[i] = null; try { fallbackTypeGenerator.GenerateInstance(parameters); violations.Add("Not guarded against nulls: " + constructor + ", Not guarded parameter: " + constructor.GetDescriptionForParameter(i)); } catch (TargetInvocationException exception) { if (exception.InnerException.GetType() == typeof(ArgumentNullException)) { //do nothing, this is the expected case } else { throw; } } } } }
public override void TearDown() { base.TearDown(); classConstructor1Wrapper = null; classConstructor2Wrapper = null; classConstructor3Wrapper = null; classConstructor4Wrapper = null; structConstructor1Wrapper = null; structConstructor2Wrapper = null; structConstructor3Wrapper = null; structConstructor4Wrapper = null; }
public override void Setup() { base.Setup(); classConstructor1Wrapper = ReflectionUtility.CreateConstructorWrapper(typeof(DummyClass)); classConstructor2Wrapper = ReflectionUtility.CreateConstructorWrapper(typeof(DummyClass).GetConstructor(new[] { typeof(int) })); classConstructor3Wrapper = ReflectionUtility.CreateConstructorWrapper(typeof(DummyClass).GetConstructor(new[] { typeof(int), typeof(string) })); classConstructor4Wrapper = ReflectionUtility.CreateConstructorWrapper(typeof(DummyClass).GetConstructor(new[] { typeof(int), typeof(string), typeof(object) })); structConstructor1Wrapper = ReflectionUtility.CreateConstructorWrapper(typeof(DummyStruct)); structConstructor2Wrapper = ReflectionUtility.CreateConstructorWrapper(typeof(DummyStruct).GetConstructor(new[] { typeof(int) })); structConstructor3Wrapper = ReflectionUtility.CreateConstructorWrapper(typeof(DummyStruct).GetConstructor(new[] { typeof(int), typeof(string) })); structConstructor4Wrapper = ReflectionUtility.CreateConstructorWrapper(typeof(DummyStruct).GetConstructor(new[] { typeof(int), typeof(string), typeof(object) })); }
public Maybe <IConstructorWrapper> PickConstructorWithLeastNonPointersParameters() { IConstructorWrapper leastParamsConstructor = null; var constructors = For(_type).GetAllPublicConstructors(); var numberOfParams = int.MaxValue; foreach (var typeConstructor in constructors) { if ( typeConstructor.HasNonPointerArgumentsOnly() && typeConstructor.HasLessParametersThan(numberOfParams)) { leastParamsConstructor = typeConstructor; numberOfParams = typeConstructor.GetParametersCount(); } } return(Maybe.Wrap(leastParamsConstructor)); }
public InjectableEmptyConstructor(Type concreteType) : base(emptyAttributeProvider) { wrapper = ReflectionUtility.CreateConstructorWrapper(concreteType); }
public ConstructorWrapperToIMethod(IConstructorWrapper cw) { _cw = cw; }