コード例 #1
0
 private bool AreParameterSignaturesEquivalent(ActiproSoftware.SyntaxEditor.Addons.DotNet.Ast.ParameterDeclaration parameter, IParameterDeclaration unmatched)
 {
     if (unmatched.Name != parameter.Name)
     {
         return(false);
     }
     return(this.AreTypesEquivalent(unmatched.ParameterType, parameter.ParameterType));
 }
コード例 #2
0
        internal bool CreateMethod(IDomType domType, Type returnType, string methodName, IEnumerable <IParameterDeclaration> parameters, CodeDocument.CaretPositionChanger UpdateCaretPosition)
        {
            int    num    = -1;
            string str1   = string.Empty;
            string str2   = string.Empty;
            string indent = string.Empty;

            foreach (IDomMember domMember in domType.GetMembers())
            {
                IAstNode astNode1 = domMember as IAstNode;
                if (domMember.Name == methodName)
                {
                    MethodDeclaration method = domMember as MethodDeclaration;
                    if (method != null)
                    {
                        List <IParameterDeclaration> list = new List <IParameterDeclaration>(parameters);
                        if (list.Count == method.Parameters.Count)
                        {
                            foreach (IAstNode astNode2 in (IEnumerable)method.Parameters)
                            {
                                ActiproSoftware.SyntaxEditor.Addons.DotNet.Ast.ParameterDeclaration parameter = astNode2 as ActiproSoftware.SyntaxEditor.Addons.DotNet.Ast.ParameterDeclaration;
                                if (parameter != null)
                                {
                                    for (int index = 0; index < list.Count; ++index)
                                    {
                                        if (this.AreParameterSignaturesEquivalent(parameter, list[index]))
                                        {
                                            list.RemoveAt(index);
                                            break;
                                        }
                                    }
                                }
                            }
                            if (list.Count == 0 && (method.ReturnType != null ? this.AreTypesEquivalent(returnType, method.ReturnType) : returnType.FullName.Equals("System.Void", StringComparison.OrdinalIgnoreCase)))
                            {
                                int offset = astNode1 != null?this.FindMethodBodyIndex(method) : -1;

                                return(UpdateCaretPosition(offset));
                            }
                        }
                    }
                }
                if (astNode1 != null && this.IsAstNodeValid(astNode1) && astNode1.EndOffset > num)
                {
                    num    = astNode1.EndOffset;
                    indent = this.GetLeadingWhitespaceForLine(astNode1.StartOffset);
                    str1   = "\r\n\r\n";
                }
            }
            if (num == -1)
            {
                foreach (IDomType domType1 in (IEnumerable)this.codeProject.ProjectResolver.SourceProjectContent.GetTypesForSourceKey(this.filename, false))
                {
                    if (string.Equals(domType1.FullName, domType.FullName, StringComparison.Ordinal))
                    {
                        domType = domType1;
                        break;
                    }
                }
                IAstNode astNode = domType as IAstNode;
                if (astNode != null && this.IsAstNodeValid(astNode))
                {
                    num = Math.Max(0, astNode.EndOffset - this.codeDocumentType.ClassEndToken.Length);
                    string whitespaceForLine = this.GetLeadingWhitespaceForLine(num);
                    str2   = "\r\n" + whitespaceForLine;
                    indent = whitespaceForLine + "\t";
                    str1   = "\r\n";
                }
            }
            if (num == -1)
            {
                return(false);
            }
            int    bodyInsertionOffset;
            string text = str1 + this.codeDocumentType.CreateMethod(indent, returnType, methodName, parameters, out bodyInsertionOffset) + str2;

            this.document.InsertText(DocumentModificationType.AutoFormat, num, text);
            return(UpdateCaretPosition(num + bodyInsertionOffset));
        }