Browse Source

Fixed NullReferenceException when converting C# statements like "if (a != null) b.c();"

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@991 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
3175901033
  1. 5
      src/Libraries/NRefactory/Project/Src/Parser/Visitors/CSharpConstructsVisitor.cs
  2. 23
      src/Libraries/NRefactory/Test/Output/VBNet/CSharpToVBConverterTest.cs

5
src/Libraries/NRefactory/Project/Src/Parser/Visitors/CSharpConstructsVisitor.cs

@ -101,7 +101,10 @@ namespace ICSharpCode.NRefactory.Parser @@ -101,7 +101,10 @@ namespace ICSharpCode.NRefactory.Parser
}
if (ident != null && se != null) {
InvocationExpression ie = se.Expression as InvocationExpression;
if (ie != null && (ie.TargetObject as IdentifierExpression).Identifier == ident.Identifier) {
if (ie != null &&
ie.TargetObject is IdentifierExpression &&
(ie.TargetObject as IdentifierExpression).Identifier == ident.Identifier)
{
ReplaceCurrentNode(new RaiseEventStatement(ident.Identifier, ie.Arguments));
}
}

23
src/Libraries/NRefactory/Test/Output/VBNet/CSharpToVBConverterTest.cs

@ -124,6 +124,29 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -124,6 +124,29 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
"RaiseEvent MyEvent(Me, EventArgs.Empty)");
}
[Test]
public void IfStatementSimilarToRaiseEvent()
{
TestStatement("if (FullImage != null) DrawImage();",
"If FullImage IsNot Nothing Then\n" +
"\tDrawImage()\n" +
"End If");
// regression test:
TestStatement("if (FullImage != null) e.DrawImage();",
"If FullImage IsNot Nothing Then\n" +
"\te.DrawImage()\n" +
"End If");
// with braces:
TestStatement("if (FullImage != null) { DrawImage(); }",
"If FullImage IsNot Nothing Then\n" +
"\tDrawImage()\n" +
"End If");
TestStatement("if (FullImage != null) { e.DrawImage(); }",
"If FullImage IsNot Nothing Then\n" +
"\te.DrawImage()\n" +
"End If");
}
[Test]
public void AnonymousMethod()
{

Loading…
Cancel
Save