示例#1
0
        private void InitializeObject(IBuilderContext context, object existing, string id, ICreationPolicy policy)
        {
            Type            type        = existing.GetType();
            ConstructorInfo constructor = policy.SelectConstructor(context, type, id);

            if (constructor == null)
            {
                if (type.IsValueType)
                {
                    return;
                }
                throw new ArgumentException(Properties.Resources.NoAppropriateConstructor);
            }

            object[] parms = policy.GetParameters(context, type, id, constructor);

            MethodBase method = (MethodBase)constructor;

            Guard.ValidateMethodParameters(method, parms, existing.GetType());

            if (TraceEnabled(context))
            {
                TraceBuildUp(context, type, id, Properties.Resources.CallingConstructor, ParametersToTypeList(parms));
            }

            method.Invoke(existing, parms);
        }
        public override object BuildUp(IBuilderContext context,
                                       object buildKey,
                                       object existing)
        {
            ICreationPolicy creationPolicy = context.Policies.Get <ICreationPolicy>(buildKey);
            IInterfaceInterceptionPolicy interceptionPolicy = context.Policies.Get <IInterfaceInterceptionPolicy>(buildKey);
            Type typeToBuild;

            if (creationPolicy != null &&
                creationPolicy.SupportsReflection &&
                interceptionPolicy != null &&
                TryGetTypeFromBuildKey(buildKey, out typeToBuild))
            {
                ConstructorInfo ctor       = creationPolicy.GetConstructor(context, buildKey);
                object[]        ctorParams = creationPolicy.GetParameters(context, ctor);
                Type            originalType;

                if (!TryGetTypeFromBuildKey(context.OriginalBuildKey, out originalType))
                {
                    originalType = typeToBuild;
                }

                buildKey = InterceptInterface(context, typeToBuild, originalType, interceptionPolicy, ctor, ctorParams);
            }

            return(base.BuildUp(context, buildKey, existing));
        }
        public override object BuildUp(IBuilderContext context,
                                       object buildKey,
                                       object existing)
        {
            ICreationPolicy            creationPolicy     = context.Policies.Get <ICreationPolicy>(buildKey);
            IVirtualInterceptionPolicy interceptionPolicy = context.Policies.Get <IVirtualInterceptionPolicy>(buildKey);
            Type typeToBuild;

            if (creationPolicy != null &&
                creationPolicy.SupportsReflection &&
                interceptionPolicy != null &&
                TryGetTypeFromBuildKey(buildKey, out typeToBuild))
            {
                ConstructorInfo ctor       = creationPolicy.GetConstructor(context, buildKey);
                object[]        ctorParams = creationPolicy.GetParameters(context, ctor);

                buildKey = InterceptClass(context, typeToBuild, interceptionPolicy, ctorParams);
            }

            return(base.BuildUp(context, buildKey, existing));
        }
        private static void InitializeObject(IBuilderContext context, object existing, string id, ICreationPolicy policy)
        {
            Type            type        = existing.GetType();
            ConstructorInfo constructor = policy.SelectConstructor(context, type, id);

            if (constructor == null)
            {
                if (type.IsValueType)
                {
                    return;
                }
                throw new ArgumentException(Resources.NoAppropriateConstructor);
            }

            object[] parms = policy.GetParameters(context, type, id, constructor);

            MethodBase method = (MethodBase)constructor;

            ValidateMethodParameters(method, parms, existing.GetType());
            method.Invoke(existing, parms);
        }
示例#5
0
 private void InitializeObject(IBuilderContext context, object existing, string id, ICreationPolicy policy)
 {
     Type type = existing.GetType();
     ConstructorInfo constructor = policy.SelectConstructor(context, type, id);
     if (constructor == null)
     {
         if (!type.IsValueType)
         {
             throw new ArgumentException(Resources.NoAppropriateConstructor);
         }
     }
     else
     {
         object[] parameters = policy.GetParameters(context, type, id, constructor);
         MethodBase methodInfo = constructor;
         Guard.ValidateMethodParameters(methodInfo, parameters, existing.GetType());
         if (base.TraceEnabled(context))
         {
             base.TraceBuildUp(context, type, id, Resources.CallingConstructor, new object[] { base.ParametersToTypeList(parameters) });
         }
         methodInfo.Invoke(existing, parameters);
     }
 }
        private static void InitializeObject(IBuilderContext context, object existing, string id, ICreationPolicy policy)
        {
            Type type = existing.GetType();
            ConstructorInfo constructor = policy.SelectConstructor(context, type, id);

            if (constructor == null)
            {
                if (type.IsValueType)
                    return;
                throw new ArgumentException(Resources.NoAppropriateConstructor);
            }

            object[] parms = policy.GetParameters(context, type, id, constructor);

            MethodBase method = (MethodBase) constructor;
            ValidateMethodParameters(method, parms, existing.GetType());
            method.Invoke(existing, parms);
        }
        private void InitializeObject(IBuilderContext context, object existing, string id, ICreationPolicy policy)
        {
            Type type = existing.GetType();
            ConstructorInfo constructor = policy.SelectConstructor(context, type, id);

            if (constructor == null)
            {
                if (type.IsValueType)
                    return;
                throw new ArgumentException(Properties.Resources.NoAppropriateConstructor);
            }

            object[] parms = policy.GetParameters(context, type, id, constructor);

            MethodBase method = (MethodBase)constructor;
            Guard.ValidateMethodParameters(method, parms, existing.GetType());

            if (TraceEnabled(context))
                TraceBuildUp(context, type, id, Properties.Resources.CallingConstructor, ParametersToTypeList(parms));

            method.Invoke(existing, parms);
        }