Ejemplo n.º 1
0
        public InjectableConstructor(ConstructorInfo constructor, IInjectableParameter[] parameters) : base(constructor)
        {
            this.parameters = parameters;

            wrapper   = constructor.CreateWrapper();
            arguments = new object[parameters.Length];
        }
Ejemplo n.º 2
0
        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;
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public override void TearDown()
        {
            base.TearDown();

            classConstructor1Wrapper = null;
            classConstructor2Wrapper = null;
            classConstructor3Wrapper = null;
            classConstructor4Wrapper = null;

            structConstructor1Wrapper = null;
            structConstructor2Wrapper = null;
            structConstructor3Wrapper = null;
            structConstructor4Wrapper = null;
        }
Ejemplo n.º 4
0
        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) }));
        }
Ejemplo n.º 5
0
        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));
        }
Ejemplo n.º 6
0
 public InjectableEmptyConstructor(Type concreteType) : base(emptyAttributeProvider)
 {
     wrapper = ReflectionUtility.CreateConstructorWrapper(concreteType);
 }
        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 override void TearDown()
        {
            base.TearDown();

            classConstructor1Wrapper = null;
            classConstructor2Wrapper = null;
            classConstructor3Wrapper = null;
            classConstructor4Wrapper = null;

            structConstructor1Wrapper = null;
            structConstructor2Wrapper = null;
            structConstructor3Wrapper = null;
            structConstructor4Wrapper = null;
        }
Ejemplo n.º 9
0
 public ConstructorWrapperToIMethod(IConstructorWrapper cw)
 {
     _cw = cw;
 }