private string GetMethodContentsFor(SyntaxTree syntaxTree, StringBuilderDocument document, string methodName, out bool wasFound) { ICSharpCode.NRefactory.CSharp.NamespaceDeclaration namespaceDecl = null; TypeDeclaration classDecl = null; MethodDeclaration methodDecl = null; BlockStatement blockStatement = null; string toReturn = null; ICSharpCode.NRefactory.TextLocation? start = null; ICSharpCode.NRefactory.TextLocation? end = null; foreach (var child in syntaxTree.Children) { if (child is ICSharpCode.NRefactory.CSharp.NamespaceDeclaration) { namespaceDecl = child as NamespaceDeclaration; break; } } if (namespaceDecl != null) { foreach (var child in namespaceDecl.Children) { if (child is TypeDeclaration) { classDecl = child as TypeDeclaration; break; } } } if (classDecl != null) { foreach (var child in classDecl.Children) { if (child is MethodDeclaration && (child as MethodDeclaration).Name == "On" + methodName) { methodDecl = child as MethodDeclaration; break; } } } if (methodDecl != null) { foreach (var child in methodDecl.Children) { if (child is BlockStatement) { blockStatement = child as BlockStatement; break; } } } if (blockStatement != null) { foreach (var child in blockStatement.Children) { if ((child is CSharpTokenNode) == false) { if (start == null) { start = child.StartLocation; } end = child.EndLocation; } } } if (start.HasValue) { int offset = document.GetOffset(start.Value); int length = document.GetOffset(end.Value) - offset; wasFound = true; return document.GetText(offset, length); } else if (blockStatement != null) { // we found a pure empty method wasFound = true; return ""; } else { wasFound = false; return null; } }