コード例 #1
0
        /// <summary>
        /// Called during the chain of responsibility for a build operation.
        /// </summary>
        /// <param name="context">The context for the operation.</param>
        public override void PreBuildUp(IBuilderContext context)
        {
            DynamicBuildPlanGenerationContext ilContext = (DynamicBuildPlanGenerationContext)(context.Existing);

            IPropertySelectorPolicy selector = context.Policies.Get <IPropertySelectorPolicy>(context.BuildKey);

            foreach (SelectedProperty property in selector.SelectProperties(context))
            {
                // Set the current operation to resolving
                ilContext.IL.Emit(OpCodes.Ldstr, property.Property.Name);
                ilContext.EmitLoadContext();
                ilContext.IL.EmitCall(OpCodes.Call, setCurrentOperationToResolvingPropertyValue, null);

                // Resolve the property value
                ilContext.EmitLoadExisting();
                ilContext.EmitResolveDependency(property.Property.PropertyType, property.Key);

                // Set the current operation to setting
                ilContext.IL.Emit(OpCodes.Ldstr, property.Property.Name);
                ilContext.EmitLoadContext();
                ilContext.IL.EmitCall(OpCodes.Call, setCurrentOperationToSettingProperty, null);

                // Call the property setter
                ilContext.IL.EmitCall(OpCodes.Callvirt, property.Property.GetSetMethod(), null);
            }

            // Clear the current operation
            ilContext.EmitClearCurrentOperation();
        }
コード例 #2
0
        /// <summary>
        /// Called during the chain of responsibility for a build operation.
        /// </summary>
        /// <param name="context">The context for the operation.</param>
        public override void PreBuildUp(IBuilderContext context)
        {
            DynamicBuildPlanGenerationContext ilContext = (DynamicBuildPlanGenerationContext)(context.Existing);

            IPropertySelectorPolicy selector = context.Policies.Get <IPropertySelectorPolicy>(context.BuildKey);

            foreach (SelectedProperty property in selector.SelectProperties(context))
            {
                ilContext.EmitLoadExisting();
                ilContext.EmitResolveDependency(property.Property.PropertyType, property.Key);
                ilContext.IL.EmitCall(OpCodes.Callvirt, property.Property.GetSetMethod(), null);
            }
        }
コード例 #3
0
 private static void ResolveProperties(IBuilderContext context, IPropertySelectorPolicy propertySelector,
                                       IPolicyList resolverPolicyDestination, Dictionary <string, StepScopeDependency> properties)
 {
     foreach (var property in propertySelector.SelectProperties(context, resolverPolicyDestination))
     {
         var namedTypeResolver = property.Resolver as NamedTypeDependencyResolverPolicy;
         if (namedTypeResolver != null)
         {
             var type = namedTypeResolver.Type;
             var name = namedTypeResolver.Name;
             if (StepScopeSynchronization.IsStepScope(type, name))
             {
                 properties[property.Property.Name] = new StepScopeDependency(type, name);
             }
         }
     }
 }
コード例 #4
0
        /// <summary>
        /// Called during the chain of responsibility for a build operation.
        /// </summary>
        /// <param name="context">The context for the operation.</param>
        public override void PreBuildUp(IBuilderContext context)
        {
            DynamicBuildPlanGenerationContext ilContext = (DynamicBuildPlanGenerationContext)(context.Existing);

            IPropertySelectorPolicy selector            = context.Policies.Get <IPropertySelectorPolicy>(context.BuildKey);
            LocalBuilder            resolving           = ilContext.IL.DeclareLocal(typeof(bool));
            LocalBuilder            currentPropertyName = ilContext.IL.DeclareLocal(typeof(string));

            ilContext.IL.BeginExceptionBlock();

            foreach (SelectedProperty property in selector.SelectProperties(context))
            {
                // Resolve the property value
                ilContext.IL.Emit(OpCodes.Ldstr, property.Property.Name);
                ilContext.IL.Emit(OpCodes.Stloc, currentPropertyName);
                ilContext.IL.Emit(OpCodes.Ldc_I4_1);
                ilContext.IL.Emit(OpCodes.Stloc, resolving);
                ilContext.EmitLoadExisting();
                ilContext.EmitResolveDependency(property.Property.PropertyType, property.Key);

                // Call the property setter
                ilContext.IL.Emit(OpCodes.Ldc_I4_0);
                ilContext.IL.Emit(OpCodes.Stloc, resolving);
                ilContext.IL.EmitCall(OpCodes.Callvirt, property.Property.GetSetMethod(), null);
            }

            // Catch any exceptions in the setting of the properties
            ilContext.IL.BeginCatchBlock(typeof(Exception));
            Label failedWhileResolving = ilContext.IL.DefineLabel();

            ilContext.IL.Emit(OpCodes.Ldloc, resolving);
            ilContext.IL.Emit(OpCodes.Brtrue, failedWhileResolving);
            ilContext.IL.Emit(OpCodes.Rethrow);

            ilContext.IL.MarkLabel(failedWhileResolving);
            ilContext.IL.Emit(OpCodes.Ldloc, currentPropertyName);
            ilContext.IL.EmitCall(OpCodes.Call, throwOnFailedPropertyValueResolution, null);
            ilContext.IL.EndExceptionBlock();
        }
コード例 #5
0
        /// <summary>
        /// Called during the chain of responsibility for a build operation.
        /// </summary>
        /// <param name="context">The context for the operation.</param>
        public override void PreBuildUp(IBuilderContext context)
        {
            Guard.ArgumentNotNull(context, "context");
            DynamicBuildPlanGenerationContext ilContext = (DynamicBuildPlanGenerationContext)(context.Existing);

            IPolicyList             resolverPolicyDestination;
            IPropertySelectorPolicy selector = context.Policies.Get <IPropertySelectorPolicy>(context.BuildKey, out resolverPolicyDestination);

            bool shouldClearOperation = false;

            foreach (SelectedProperty property in selector.SelectProperties(context, resolverPolicyDestination))
            {
                shouldClearOperation = true;
                // Set the current operation to resolving
                ilContext.IL.Emit(OpCodes.Ldstr, property.Property.Name);
                ilContext.EmitLoadContext();
                ilContext.IL.EmitCall(OpCodes.Call, setCurrentOperationToResolvingPropertyValue, null);

                // Resolve the property value
                ilContext.EmitLoadExisting();
                ilContext.EmitResolveDependency(property.Property.PropertyType, property.Key);

                // Set the current operation to setting
                ilContext.IL.Emit(OpCodes.Ldstr, property.Property.Name);
                ilContext.EmitLoadContext();
                ilContext.IL.EmitCall(OpCodes.Call, setCurrentOperationToSettingProperty, null);

                // Call the property setter
                ilContext.IL.EmitCall(OpCodes.Callvirt, GetValidatedPropertySetter(property.Property), null);
            }

            // Clear the current operation
            if (shouldClearOperation)
            {
                ilContext.EmitClearCurrentOperation();
            }
        }
コード例 #6
0
 private static void ResolveProperties(IBuilderContext context, IPropertySelectorPolicy propertySelector,
     IPolicyList resolverPolicyDestination, Dictionary<string, StepScopeDependency> properties)
 {
     foreach (var property in propertySelector.SelectProperties(context, resolverPolicyDestination))
     {
         var namedTypeResolver = property.Resolver as NamedTypeDependencyResolverPolicy;
         if (namedTypeResolver != null)
         {
             var type = namedTypeResolver.Type;
             var name = namedTypeResolver.Name;
             if (StepScopeSynchronization.IsStepScope(type, name))
             {
                 properties[property.Property.Name] = new StepScopeDependency(type, name);
             }
         }
     }
 }