Exemplo n.º 1
0
        /// <summary>
        /// 重构方法
        /// </summary>
        /// <param name="replacedFunction"></param>
        /// <param name="newFunction"></param>
        private void RefactorMethod(CodeFunction replacedFunction, CodeFunction newFunction)
        {
            //清除方法参数
            while (replacedFunction.Parameters.Count > 0)
            {
                replacedFunction.RemoveParameter(replacedFunction.Parameters.Count);
            }

            //清除方法属性
            while (replacedFunction.Attributes.Count > 0)
            {
                ((CodeAttribute)replacedFunction.Attributes.Item(replacedFunction.Attributes.Count)).Delete();
            }

            //添加参数
            for (int i = 1; i <= newFunction.Parameters.Count; i++)
            {
                CodeParameter2 parameter      = newFunction.Parameters.Item(i) as CodeParameter2;
                CodeParameter2 cloneParameter = replacedFunction.AddParameter(parameter.FullName, parameter.Type.AsFullName, i) as CodeParameter2;
                cloneParameter.DefaultValue  = parameter.DefaultValue;
                cloneParameter.ParameterKind = parameter.ParameterKind;
            }

            //添加属性
            for (int i = 1; i <= newFunction.Attributes.Count; i++)
            {
                CodeAttribute2 attribute = newFunction.Attributes.Item(i) as CodeAttribute2;
                replacedFunction.AddAttribute(attribute.Name, attribute.Value, i);
            }

            //方法名
            replacedFunction.Name = newFunction.Name;
            //方法注释
            replacedFunction.Comment = newFunction.Comment;
            //方法说明
            replacedFunction.DocComment = newFunction.DocComment;
            //静态修饰
            replacedFunction.IsShared = newFunction.IsShared;
            //抽象修饰
            replacedFunction.MustImplement = newFunction.MustImplement;
            //重载修饰
            replacedFunction.CanOverride = newFunction.CanOverride;
        }
Exemplo n.º 2
0
        /// <summary>
        /// 重构方法
        /// </summary>
        /// <param name="replacedFunction"></param>
        /// <param name="newFunction"></param>
        private void RefactorMethod(CodeFunction replacedFunction, CodeFunction newFunction)
        {
            //清除方法参数
            while (replacedFunction.Parameters.Count > 0)
            {
                replacedFunction.RemoveParameter(replacedFunction.Parameters.Count);
            }

            //清除方法属性
            while (replacedFunction.Attributes.Count > 0)
            {
                ((CodeAttribute)replacedFunction.Attributes.Item(replacedFunction.Attributes.Count)).Delete();
            }

            //添加参数
            for (int i = 1; i <= newFunction.Parameters.Count; i++)
            {
                CodeParameter2 parameter = newFunction.Parameters.Item(i) as CodeParameter2;
                CodeParameter2 cloneParameter = replacedFunction.AddParameter(parameter.FullName, parameter.Type.AsFullName, i) as CodeParameter2;
                cloneParameter.DefaultValue = parameter.DefaultValue;
                cloneParameter.ParameterKind = parameter.ParameterKind;
            }

            //添加属性
            for (int i = 1; i <= newFunction.Attributes.Count; i++)
            {
                CodeAttribute2 attribute = newFunction.Attributes.Item(i) as CodeAttribute2;
                replacedFunction.AddAttribute(attribute.Name, attribute.Value, i);
            }

            //方法名
            replacedFunction.Name = newFunction.Name;
            //方法注释
            replacedFunction.Comment = newFunction.Comment;
            //方法说明
            replacedFunction.DocComment = newFunction.DocComment;
            //静态修饰
            replacedFunction.IsShared = newFunction.IsShared;
            //抽象修饰
            replacedFunction.MustImplement = newFunction.MustImplement;
            //重载修饰
            replacedFunction.CanOverride = newFunction.CanOverride;
        }