Browse Source

Fixed SD2-1071: Explicit bounds in array assignment not converted correctly between C#<-->VB.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.1@2199 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
4a374bf942
  1. 9
      src/Libraries/NRefactory/Project/Src/Visitors/ToVBNetConvertVisitor.cs
  2. 12
      src/Libraries/NRefactory/Project/Src/Visitors/VBNetConstructsConvertVisitor.cs
  3. 11
      src/Libraries/NRefactory/Test/Output/CSharp/VBToCSharpConverterTest.cs
  4. 13
      src/Libraries/NRefactory/Test/Output/VBNet/CSharpToVBConverterTest.cs

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

@ -25,6 +25,7 @@ namespace ICSharpCode.NRefactory.Visitors
// Simple event handler creation is replaced with AddressOfExpression // Simple event handler creation is replaced with AddressOfExpression
// Move Imports-statements out of namespaces // Move Imports-statements out of namespaces
// Parenthesis around Cast expressions remove - these are syntax errors in VB.NET // Parenthesis around Cast expressions remove - these are syntax errors in VB.NET
// Decrease array creation size - VB specifies upper bound instead of array length
List<INode> nodesToMoveToCompilationUnit = new List<INode>(); List<INode> nodesToMoveToCompilationUnit = new List<INode>();
@ -326,5 +327,13 @@ namespace ICSharpCode.NRefactory.Visitors
} }
return null; return null;
} }
public override object VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, object data)
{
for (int i = 0; i < arrayCreateExpression.Arguments.Count; i++) {
arrayCreateExpression.Arguments[i] = Expression.AddInteger(arrayCreateExpression.Arguments[i], -1);
}
return base.VisitArrayCreateExpression(arrayCreateExpression, data);
}
} }
} }

12
src/Libraries/NRefactory/Project/Src/Visitors/VBNetConstructsConvertVisitor.cs

@ -26,6 +26,7 @@ namespace ICSharpCode.NRefactory.Visitors
// IIF(cond, true, false) => ConditionalExpression // IIF(cond, true, false) => ConditionalExpression
// Built-in methods => Prefix with class name // Built-in methods => Prefix with class name
// Function A() \n A = SomeValue \n End Function -> convert to return statement // Function A() \n A = SomeValue \n End Function -> convert to return statement
// Array creation => add 1 to upper bound to get array length
Dictionary<string, string> usings; Dictionary<string, string> usings;
List<UsingDeclaration> addedUsings; List<UsingDeclaration> addedUsings;
@ -456,5 +457,16 @@ namespace ICSharpCode.NRefactory.Visitors
} }
return base.VisitUsingStatement(usingStatement, data); return base.VisitUsingStatement(usingStatement, data);
} }
public override object VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, object data)
{
for (int i = 0; i < arrayCreateExpression.Arguments.Count; i++) {
arrayCreateExpression.Arguments[i] = Expression.AddInteger(arrayCreateExpression.Arguments[i], 1);
}
if (arrayCreateExpression.ArrayInitializer.CreateExpressions.Count == 0) {
arrayCreateExpression.ArrayInitializer = null;
}
return base.VisitArrayCreateExpression(arrayCreateExpression, data);
}
} }
} }

11
src/Libraries/NRefactory/Test/Output/CSharp/VBToCSharpConverterTest.cs

@ -598,5 +598,16 @@ static int static_Test2_j = 0;");
{ {
TestStatement("CType(obj, IDisposable).Dispose()", "((IDisposable)obj).Dispose();"); TestStatement("CType(obj, IDisposable).Dispose()", "((IDisposable)obj).Dispose();");
} }
[Test]
public void ArrayCreationUpperBound()
{
TestStatement("Dim i As String() = New String(1) {}",
"string[] i = new string[2];");
TestStatement("Dim i As String() = New String(1) {\"0\", \"1\"}",
"string[] i = new string[2] {\"0\", \"1\"};");
TestStatement("Dim i As String(,) = New String(5, 5) {}",
"string[,] i = new string[6, 6];");
}
} }
} }

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

@ -224,7 +224,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
"\tReturn argument * 2\n" + "\tReturn argument * 2\n" +
"End Function"); "End Function");
} }
*/ */
[Test] [Test]
public void RegisterEvent() public void RegisterEvent()
@ -449,5 +449,16 @@ End Class
{ {
TestStatement("a = (int)number;", "a = CInt(number)"); TestStatement("a = (int)number;", "a = CInt(number)");
} }
[Test]
public void ArrayCreationUpperBound()
{
TestStatement("string[] i = new string[2];",
"Dim i As String() = New String(1) {}");
TestStatement("string[] i = new string[2] { \"0\", \"1\" };",
"Dim i As String() = New String(1) {\"0\", \"1\"}");
TestStatement("string[,] i = new string[6, 6];",
"Dim i As String(,) = New String(5, 5) {}");
}
} }
} }

Loading…
Cancel
Save