Implement VB's implicit enumerables as implicit arrays (and enable test)
This commit is contained in:
Родитель
e588cacd11
Коммит
9b922946a7
|
@ -911,7 +911,11 @@ namespace RefactoringEssentials.CSharp.Converter
|
|||
{
|
||||
if (node.Initializers.Count == 0 && node.Parent is VBSyntax.ArrayCreationExpressionSyntax)
|
||||
return null;
|
||||
return SyntaxFactory.InitializerExpression(SyntaxKind.CollectionInitializerExpression, SyntaxFactory.SeparatedList(node.Initializers.Select(i => (ExpressionSyntax)i.Accept(this))));
|
||||
var initializer = SyntaxFactory.InitializerExpression(SyntaxKind.CollectionInitializerExpression, SyntaxFactory.SeparatedList(node.Initializers.Select(i => (ExpressionSyntax)i.Accept(this))));
|
||||
var typeInfo = semanticModel.GetTypeInfo(node);
|
||||
return typeInfo.Type == null && (typeInfo.ConvertedType?.SpecialType == SpecialType.System_Collections_IEnumerable || typeInfo.ConvertedType?.IsKind(SymbolKind.ArrayType) == true)
|
||||
? (CSharpSyntaxNode) SyntaxFactory.ImplicitArrayCreationExpression(initializer)
|
||||
: initializer;
|
||||
}
|
||||
|
||||
public override CSharpSyntaxNode VisitObjectCollectionInitializer(VBSyntax.ObjectCollectionInitializerSyntax node)
|
||||
|
|
|
@ -43,6 +43,28 @@ class TestClass
|
|||
}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FullyTypeInferredEnumerableCreation()
|
||||
{
|
||||
TestConversionVisualBasicToCSharp(@"Class TestClass
|
||||
Private Sub TestMethod()
|
||||
Dim strings = { ""1"", ""2"" }
|
||||
End Sub
|
||||
End Class", @"using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.VisualBasic;
|
||||
|
||||
class TestClass
|
||||
{
|
||||
private void TestMethod()
|
||||
{
|
||||
var strings = new[] { ""1"", ""2"" };
|
||||
}
|
||||
}");
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void StringConcatenationAssignment()
|
||||
{
|
||||
|
|
|
@ -404,7 +404,7 @@ class TestClass
|
|||
}");
|
||||
}
|
||||
|
||||
[Fact(Skip = "Not implemented!")]
|
||||
[Fact]
|
||||
public void JaggedArrayInitializationStatement()
|
||||
{
|
||||
TestConversionVisualBasicToCSharp(@"Class TestClass
|
||||
|
|
Загрузка…
Ссылка в новой задаче