public InjectPropertyInfo(
     PropertyInfo propertyInfo,
     InjectableInfo injectableInfo)
 {
     InjectableInfo = injectableInfo;
     PropertyInfo   = propertyInfo;
 }
 public InjectParameterInfo(
     ParameterInfo parameterInfo,
     InjectableInfo injectableInfo)
 {
     InjectableInfo = injectableInfo;
     ParameterInfo  = parameterInfo;
 }
 public InjectFieldInfo(
     FieldInfo fieldInfo,
     InjectableInfo injectableInfo)
 {
     InjectableInfo = injectableInfo;
     FieldInfo      = fieldInfo;
 }
        void EmitNewInjectableInfoInstructions(
            List <Instruction> instructions,
            InjectableInfo injectableInfo,
            TypeDefinition typeDef)
        {
            if (injectableInfo.Optional)
            {
                instructions.Add(Instruction.Create(OpCodes.Ldc_I4_1));
            }
            else
            {
                instructions.Add(Instruction.Create(OpCodes.Ldc_I4_0));
            }

            AddObjectInstructions(instructions, injectableInfo.Identifier);

            instructions.Add(Instruction.Create(OpCodes.Ldstr, injectableInfo.MemberName));

            instructions.Add(Instruction.Create(OpCodes.Ldtoken, CreateGenericInstanceIfNecessary(injectableInfo.MemberType, typeDef.GenericParameters)));

            instructions.Add(Instruction.Create(OpCodes.Call, _getTypeFromHandleMethod));

            AddObjectInstructions(instructions, injectableInfo.DefaultValue);

            instructions.Add(Instruction.Create(OpCodes.Ldc_I4, (int)injectableInfo.SourceType));

            instructions.Add(Instruction.Create(OpCodes.Newobj, _injectableInfoConstructor));
        }
        void AddInjectableMemberInstructions(
            List <Instruction> instructions,
            InjectableInfo injectableInfo, string name,
            TypeDefinition typeDef, TypeReference genericTypeDef,
            MethodDefinition methodDef)
        {
            instructions.Add(Instruction.Create(OpCodes.Ldnull));
            instructions.Add(Instruction.Create(OpCodes.Ldftn, methodDef.ChangeDeclaringType(genericTypeDef)));
            instructions.Add(Instruction.Create(OpCodes.Newobj, _funcMemberSetter));

            EmitNewInjectableInfoInstructions(
                instructions, injectableInfo, typeDef);

            instructions.Add(Instruction.Create(OpCodes.Newobj, _injectMemberInfoConstructor));
        }
        public static InjectContext SpawnInjectContext(
            DiContainer container, InjectableInfo injectableInfo, InjectContext currentContext,
            object targetInstance, Type targetType, object concreteIdentifier)
        {
            var context = SpawnInjectContext(container, injectableInfo.MemberType);

            context.ObjectType         = targetType;
            context.ParentContext      = currentContext;
            context.ObjectInstance     = targetInstance;
            context.Identifier         = injectableInfo.Identifier;
            context.MemberName         = injectableInfo.MemberName;
            context.Optional           = injectableInfo.Optional;
            context.SourceType         = injectableInfo.SourceType;
            context.FallBackValue      = injectableInfo.DefaultValue;
            context.ConcreteIdentifier = concreteIdentifier;

            return(context);
        }