Skip to content

Commit

Permalink
Only use object collection initializer for object creation
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamTheCoder committed Mar 6, 2020
1 parent ba7009f commit d94a595
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions CodeConverter/VB/NodesVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1352,7 +1352,7 @@ public override VisualBasicSyntaxNode VisitInitializerExpression(CSS.Initializer
SyntaxFactory.SeparatedList(expressions.OfType<ExpressionSyntax>())
);

var isObjectCollection = _semanticModel.GetTypeInfo(node.Parent).Type?.CanSupportCollectionInitializer(_semanticModel.GetEnclosingSymbol<INamedTypeSymbol>(node.SpanStart, default)) == true;
var isObjectCollection = node.IsParentKind(CS.SyntaxKind.ObjectCreationExpression) && _semanticModel.GetTypeInfo(node.Parent).Type?.CanSupportCollectionInitializer(_semanticModel.GetEnclosingSymbol<INamedTypeSymbol>(node.SpanStart, default)) == true;

return isObjectCollection ? (VisualBasicSyntaxNode) SyntaxFactory.ObjectCollectionInitializer(collectionInitializerSyntax) : collectionInitializerSyntax;
}
Expand Down Expand Up @@ -1437,18 +1437,18 @@ private IEnumerable<QueryClauseSyntax> ConvertQueryBody(CSS.QueryBodySyntax body
SyntaxFactory.SingletonSeparatedList(aggregationRangeVariableSyntax));
if (body.Continuation.Body != null) {
foreach (var clause in ConvertQueryBody(body.Continuation.Body)) {
var groupKeyAccesses = clause.DescendantNodes().OfType<MemberAccessExpressionSyntax>()
var groupKeyAccesses = clause.DescendantNodes().OfType<CSS.MemberAccessExpressionSyntax>()
.Where(node => IsGroupKeyAccess(node, csGroupId));
yield return clause.ReplaceNodes(groupKeyAccesses, (_, rewrite) => SyntaxFactory.IdentifierName(newGroupKeyName));
}
}
}
}

private static bool IsGroupKeyAccess(MemberAccessExpressionSyntax node, SyntaxToken csGroupId)
private static bool IsGroupKeyAccess(CSS.MemberAccessExpressionSyntax node, SyntaxToken csGroupId)
{
return node.Name.Identifier.Text == "Key" &&
node.Expression is IdentifierNameSyntax ins &&
node.Expression is CSS.IdentifierNameSyntax ins &&
ins.Identifier.Text == csGroupId.Text;
}

Expand Down

0 comments on commit d94a595

Please sign in to comment.