From cb8f1d107897073bad4f20e79f19c84e5a9aa8d1 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 13 May 2007 16:38:15 +0000 Subject: [PATCH] Fixed NullReferenceException in ToVBNetConvertVisitor when doing snippet conversion. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.1@2518 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Src/Visitors/ToVBNetConvertVisitor.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Libraries/NRefactory/Project/Src/Visitors/ToVBNetConvertVisitor.cs b/src/Libraries/NRefactory/Project/Src/Visitors/ToVBNetConvertVisitor.cs index eaed1f95ce..64c008d4ff 100644 --- a/src/Libraries/NRefactory/Project/Src/Visitors/ToVBNetConvertVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/Visitors/ToVBNetConvertVisitor.cs @@ -109,11 +109,13 @@ namespace ICSharpCode.NRefactory.Visitors for (int i = 1;; i++) { string name = "ConvertedAnonymousMethod" + i; bool ok = true; - foreach (object c in currentType.Children) { - MethodDeclaration method = c as MethodDeclaration; - if (method != null && method.Name == name) { - ok = false; - break; + if (currentType != null) { + foreach (object c in currentType.Children) { + MethodDeclaration method = c as MethodDeclaration; + if (method != null && method.Name == name) { + ok = false; + break; + } } } if (ok) @@ -162,7 +164,9 @@ namespace ICSharpCode.NRefactory.Visitors { MethodDeclaration method = new MethodDeclaration(GetAnonymousMethodName(), Modifiers.Private, new TypeReference("System.Void"), anonymousMethodExpression.Parameters, null); method.Body = anonymousMethodExpression.Body; - currentType.Children.Add(method); + if (currentType != null) { + currentType.Children.Add(method); + } ReplaceCurrentNode(new AddressOfExpression(new IdentifierExpression(method.Name))); return null; } @@ -173,7 +177,7 @@ namespace ICSharpCode.NRefactory.Visitors || assignmentExpression.Op == AssignmentOperatorType.Subtract) { string methodName = GetMethodNameOfDelegateCreation(assignmentExpression.Right); - if (methodName != null) { + if (methodName != null && currentType != null) { foreach (object c in currentType.Children) { MethodDeclaration method = c as MethodDeclaration; if (method != null && method.Name == methodName) {