Exemple #1
0
 private void RefactorMethodNamesInStatement(CodeStatement statement, string newName)
 {
     if (typeof(CodeVariableDeclarationStatement) == statement.GetType())
     {
         CodeVariableDeclarationStatement vdeclStatement = (CodeVariableDeclarationStatement)statement;
         if (vdeclStatement.InitExpression != null)
         {
             if (typeof(CodeCastExpression) == vdeclStatement.InitExpression.GetType())
             {
                 CodeCastExpression castExp = (CodeCastExpression)vdeclStatement.InitExpression;
                 if (typeof(CodeMethodInvokeExpression) == castExp.Expression.GetType())
                 {
                     CodeMethodInvokeExpression miExp = (CodeMethodInvokeExpression)castExp.Expression;
                     miExp.Method.MethodName = PascalCaseConverterHelper.GetPascalCaseMethodName(miExp.Method.MethodName);
                 }
             }
             else if (typeof(CodeMethodInvokeExpression) == vdeclStatement.InitExpression.GetType())
             {
                 CodeMethodInvokeExpression miExp = (CodeMethodInvokeExpression)vdeclStatement.InitExpression;
                 miExp.Method.MethodName = PascalCaseConverterHelper.GetPascalCaseMethodName(miExp.Method.MethodName);
             }
         }
     }
     else if (typeof(CodeExpressionStatement) == statement.GetType())
     {
         CodeExpressionStatement ceStatement = (CodeExpressionStatement)statement;
         if (typeof(CodeMethodInvokeExpression) == ceStatement.Expression.GetType())
         {
             CodeMethodInvokeExpression miExp = (CodeMethodInvokeExpression)ceStatement.Expression;
             miExp.Method.MethodName = PascalCaseConverterHelper.GetPascalCaseMethodName(miExp.Method.MethodName);
         }
     }
     else if (typeof(CodeAssignStatement) == statement.GetType())
     {
         CodeAssignStatement asnStatement = (CodeAssignStatement)statement;
         if (typeof(CodeCastExpression) == asnStatement.Right.GetType())
         {
             CodeCastExpression castExp = (CodeCastExpression)asnStatement.Right;
             if (typeof(CodeMethodInvokeExpression) == castExp.Expression.GetType())
             {
                 CodeMethodInvokeExpression miExp = (CodeMethodInvokeExpression)castExp.Expression;
                 miExp.Method.MethodName = PascalCaseConverterHelper.GetPascalCaseMethodName(miExp.Method.MethodName);
             }
         }
         else if (typeof(CodeMethodInvokeExpression) == asnStatement.Right.GetType())
         {
             CodeMethodInvokeExpression miExp = (CodeMethodInvokeExpression)asnStatement.Right;
             miExp.Method.MethodName = PascalCaseConverterHelper.GetPascalCaseMethodName(miExp.Method.MethodName);
         }
     }
     else if (typeof(CodeMethodReturnStatement) == statement.GetType())
     {
         CodeMethodReturnStatement retStatement = (CodeMethodReturnStatement)statement;
         if (typeof(CodeMethodInvokeExpression) == retStatement.Expression.GetType())
         {
             CodeMethodInvokeExpression miExp = (CodeMethodInvokeExpression)retStatement.Expression;
             miExp.Method.MethodName = PascalCaseConverterHelper.GetPascalCaseMethodName(miExp.Method.MethodName);
         }
     }
 }
Exemple #2
0
        /// <summary>
        /// Contains the core logic for converting a method name to Pascal case.
        /// </summary>
        private void ConvertMethod(CodeTypeMemberExtension memberExtension)
        {
            // Get a copy of the original name.
            string oldName = memberExtension.ExtendedObject.Name;
            // Change the method name to Pascal case.
            string newName = PascalCaseConverterHelper.GetPascalCaseMethodName(oldName);

            memberExtension.ExtendedObject.Name = newName;
            OnMethodNameChanged(memberExtension, oldName, newName);
        }