提交 0f09364f 编写于 作者: C Cyrus Najmabadi

Tweaks

上级 faeaf7f8
......@@ -31,6 +31,7 @@ protected override SwitchExpressionArmSyntax CreateSwitchArm(SyntaxGenerator gen
=> SwitchExpressionArm(ConstantPattern(caseLabel), Exception(generator, compilation));
protected override SwitchExpressionSyntax InsertSwitchArms(SyntaxGenerator generator, SwitchExpressionSyntax switchNode, int insertLocation, List<SwitchExpressionArmSyntax> newArms)
=> switchNode.WithArms(switchNode.Arms.InsertRangeWithTrailingSeparator(insertLocation, newArms));
=> switchNode.WithArms(switchNode.Arms.InsertRangeWithTrailingSeparator(
insertLocation, newArms, SyntaxKind.CommaToken));
}
}
......@@ -8,23 +8,19 @@ namespace Microsoft.CodeAnalysis.CSharp.Extensions
{
internal static class SeparatedSyntaxListExtensions
{
public static SeparatedSyntaxList<T> InsertRangeWithTrailingSeparator<T>(this SeparatedSyntaxList<T> separatedList, int index, IEnumerable<T> nodes)
public static SeparatedSyntaxList<T> InsertRangeWithTrailingSeparator<T>(
this SeparatedSyntaxList<T> separatedList, int index, IEnumerable<T> nodes, SyntaxKind separator)
where T : SyntaxNode
{
// Could be implemented more efficiently by parameterizing the implementation of SeparatedSyntaxList<>.InsertRange
var newList = separatedList.InsertRange(index, nodes);
if (index < separatedList.Count)
return newList;
if (index >= separatedList.Count)
{
var nodesAndTokens = newList.GetWithSeparators();
var nodesAndTokens = newList.GetWithSeparators();
if (!nodesAndTokens.Last().IsNode)
return newList;
if (nodesAndTokens.Last().IsNode)
{
return SyntaxFactory.SeparatedList<T>(nodesAndTokens.Add(SyntaxFactory.Token(SyntaxKind.CommaToken)));
}
}
return newList;
return SyntaxFactory.SeparatedList<T>(nodesAndTokens.Add(SyntaxFactory.Token(separator)));
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册