Beispiel #1
0
        public override ConstructorInfo Selecter(IShifterContext context)
        {
            Assume.ArgumentNotNull(context, "context");

            var bindingFlags             = new BindingFlagsCombiner().Execute(context.Container.Options.ResolvePrivateMembers);
            var constructors             = new List <ConstructorInfo>(context.TypeToResolve.GetConstructors(bindingFlags));
            var injectMarkedConstructors = constructors.FindAll(constructor => constructor.IsDefined(typeof(InjectAttribute), false));

            if (injectMarkedConstructors.Count > 1)
            {
                throw new NotSupportedException(Strings.MultipleConstructorInjectionIsNotSupported);
            }

            if (injectMarkedConstructors.Count == 1)
            {
                return(injectMarkedConstructors[0]);
            }

            if (constructors.Count > 0)
            {
                return(constructors[0]);
            }

            return(context.TypeToResolve.GetConstructor(Type.EmptyTypes));
        }
Beispiel #2
0
        public override IEnumerable <PropertyInfo> Select(IShifterContext context)
        {
            Assume.ArgumentNotNull(context, "context");

            var bindingFlags = new BindingFlagsCombiner().Execute(context.Container.Options.ResolvePrivateMembers);
            var propertyList = new List <PropertyInfo>(context.TypeToResolve.GetProperties(bindingFlags));

            return(propertyList.Where(property => property.IsDefined(typeof(InjectAttribute), false)));
        }