public virtual T BuildUp()
        {
            var steps = new B.BuilderStepDiscovery().DiscoveryBuildSteps(typeof(T));

            if (steps == null)
            {
                return(new T()); // Factory模式
            }
            var target = new T();

            // BuildUp()执行前的切入点
            if (BeforeBuildUp != null)
            {
                BeforeBuildUp(this, new BuilderEventArgs <T>()
                {
                    Target = target
                });
            }

            foreach (var step in steps)
            {
                for (var i = 0; i < step.Times; i++)
                {
                    // BuildPart()执行前的切入点
                    if (BeforeBuildStepExecuting != null)
                    {
                        BeforeBuildStepExecuting(this,
                                                 new BuilderStepEventArgs <T>()
                        {
                            Target      = target,
                            Step        = step,
                            CurrentLoop = i
                        });
                    }
                    step.Method.Invoke(target, null);

                    // BuildPart()执行后的切入点
                    if (AfterBuildStepExecuting != null)
                    {
                        AfterBuildStepExecuting(this,
                                                new BuilderStepEventArgs <T>()
                        {
                            Target      = target,
                            Step        = step,
                            CurrentLoop = i
                        });
                    }
                }
            }

            // BuildUp()执行后的切入点
            if (AfterBuildUp != null)
            {
                AfterBuildUp(this, new BuilderEventArgs <T> {
                    Target = target
                });
            }

            return(target);
        }
Exemple #2
0
        public virtual T BuildUp()
        {
            var steps = new BuilderStepDiscovery().DiscoveryBuildSteps(typeof(T));

            if (steps == null)
            {
                return(new T()); // 没有BuildPart步骤,退化为Factory模式
            }
            var target = new T();

            foreach (var step in steps)
            {
                for (int i = 0; i < step.Times; i++)
                {
                    step.Method.Invoke(target, null);
                }
            }
            return(target);
        }