コード例 #1
0
        public MethodMaterializer(IShifterContext context)
        {
            Assume.ArgumentNotNull(context, "context");
            Assume.ArgumentNotNull(context.Instance, "context.Instance");

            this.context = context;
        }
コード例 #2
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));
        }
コード例 #3
0
        public PropertyInjector(PropertyInfo property, IShifterContext context, object value)
        {
            Assume.ArgumentNotNull(property, "property");
            Assume.ArgumentNotNull(context, "context");

            this.property = property;
            this.context  = context;
            this.value    = value;
        }
コード例 #4
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)));
        }
コード例 #5
0
        public ConstructorInjector(ConstructorInfo constructor, IShifterContext context, object[] arguments)
        {
            Assume.ArgumentNotNull(constructor, "constructor");
            Assume.ArgumentNotNull(context, "context");

            this.constructor = constructor;
            this.context     = context;
            this.arguments   = arguments;
        }
コード例 #6
0
        public MethodInjector(IShifterContext context, MethodBase method, object[] parameters)
        {
            Assume.ArgumentNotNull(context, "context");
            Assume.ArgumentNotNull(method, "method");
            Assume.ArrayNotNullOrEmpty(parameters, "parameters");

            this.context    = context;
            this.method     = method;
            this.parameters = parameters;
        }
コード例 #7
0
        public FieldInjector(IShifterContext context, FieldInfo field, object value)
        {
            Assume.ArgumentNotNull(context, "context");
            Assume.ArgumentNotNull(field, "field");
            Assume.ArgumentNotNull(value, "value");

            this.context = context;
            this.field   = field;
            this.value   = value;
        }
コード例 #8
0
ファイル: ShifterContext.cs プロジェクト: tronsoft/shifter
        public ShifterContext(Type typeToResolve, IShifterContainer container, IEnumerable <Func <IResolutionStrategy> > strategyFactoryFactories)
        {
            Assume.ArgumentNotNull(typeToResolve, "typeToResolve");
            Assume.ArgumentNotNull(container, "container");
            Assume.ArgumentNotNull(strategyFactoryFactories, "strategyFactoryFactories");

            TypeToResolve     = typeToResolve;
            Container         = container;
            StrategyFactories = strategyFactoryFactories;
        }
コード例 #9
0
        public void Initialize(IShifterContext context)
        {
            Assume.ArgumentNotNull(context, "context");

            if (context.Instance == null)
            {
                throw new TypeResolvingFailedException(string.Format(Strings.InstanceIsNull, context.TypeToResolve.Name));
            }

            InitializeImpl(context);
        }
コード例 #10
0
        public PropertyMaterializer(IShifterContext context)
        {
            Assume.ArgumentNotNull(context, "context");

            this.context = context;
        }