Browse Source

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
shortcuts
Daniel Grunwald 19 years ago
parent
commit
cb8f1d1078
  1. 18
      src/Libraries/NRefactory/Project/Src/Visitors/ToVBNetConvertVisitor.cs

18
src/Libraries/NRefactory/Project/Src/Visitors/ToVBNetConvertVisitor.cs

@ -109,11 +109,13 @@ namespace ICSharpCode.NRefactory.Visitors
for (int i = 1;; i++) { for (int i = 1;; i++) {
string name = "ConvertedAnonymousMethod" + i; string name = "ConvertedAnonymousMethod" + i;
bool ok = true; bool ok = true;
foreach (object c in currentType.Children) { if (currentType != null) {
MethodDeclaration method = c as MethodDeclaration; foreach (object c in currentType.Children) {
if (method != null && method.Name == name) { MethodDeclaration method = c as MethodDeclaration;
ok = false; if (method != null && method.Name == name) {
break; ok = false;
break;
}
} }
} }
if (ok) if (ok)
@ -162,7 +164,9 @@ namespace ICSharpCode.NRefactory.Visitors
{ {
MethodDeclaration method = new MethodDeclaration(GetAnonymousMethodName(), Modifiers.Private, new TypeReference("System.Void"), anonymousMethodExpression.Parameters, null); MethodDeclaration method = new MethodDeclaration(GetAnonymousMethodName(), Modifiers.Private, new TypeReference("System.Void"), anonymousMethodExpression.Parameters, null);
method.Body = anonymousMethodExpression.Body; method.Body = anonymousMethodExpression.Body;
currentType.Children.Add(method); if (currentType != null) {
currentType.Children.Add(method);
}
ReplaceCurrentNode(new AddressOfExpression(new IdentifierExpression(method.Name))); ReplaceCurrentNode(new AddressOfExpression(new IdentifierExpression(method.Name)));
return null; return null;
} }
@ -173,7 +177,7 @@ namespace ICSharpCode.NRefactory.Visitors
|| assignmentExpression.Op == AssignmentOperatorType.Subtract) || assignmentExpression.Op == AssignmentOperatorType.Subtract)
{ {
string methodName = GetMethodNameOfDelegateCreation(assignmentExpression.Right); string methodName = GetMethodNameOfDelegateCreation(assignmentExpression.Right);
if (methodName != null) { if (methodName != null && currentType != null) {
foreach (object c in currentType.Children) { foreach (object c in currentType.Children) {
MethodDeclaration method = c as MethodDeclaration; MethodDeclaration method = c as MethodDeclaration;
if (method != null && method.Name == methodName) { if (method != null && method.Name == methodName) {

Loading…
Cancel
Save