コード例 #1
0
        /// <summary>
        /// helper method: 按照DirectorAttribute的要求,执行相关的Builder方法
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="attribute"></param>
        private void InvokeBuildPartMethod(IAttributedBuilder builder, DirectorAttribute attribute)
        {
            switch (attribute.Method)
            {
            case "BuildPartA": builder.BuildPartA(); break;

            case "BuildPartB": builder.BuildPartB(); break;

            case "BuildPartC": builder.BuildPartC(); break;
            }
        }
コード例 #2
0
        public void BuildUp(IAttributedBuilder builder)
        {
            //获取Builder的DirectorAttribute属性
            object[] attributes = builder.GetType().GetCustomAttributes(typeof(DirectorAttribute), false);
            if (attributes.Length <= 0)
            {
                return;
            }

            DirectorAttribute[] directors = new DirectorAttribute[attributes.Length];

            for (int i = 0; i < attributes.Length; i++)
            {
                directors[i] = (DirectorAttribute)attributes[i];
            }

            //按每个DirectorAttribute优先级逆序排序后,逐个执行
            Array.Sort <DirectorAttribute>(directors);
            foreach (DirectorAttribute attribute in directors)
            {
                InvokeBuildPartMethod(builder, attribute);
            }
        }