提交 9eef7089 编写于 作者: D David Poeschl

Fix C# AddNameToArgument to support AttributeArguments

上级 94f0cdd3
......@@ -377,6 +377,34 @@ public MyAttribute(int y, byte b, string x)
await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode);
}
[WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)]
public async Task AddOptionalParameterWithOmittedCallsiteToAttributeConstructor()
{
var markup = @"
[Some(1, 2, 4)]
class SomeAttribute : System.Attribute
{
public SomeAttribute$$(int a, int b, int y = 4)
{
}
}";
var permutation = new[] {
new AddedParameterOrExistingIndex(0),
new AddedParameterOrExistingIndex(1),
AddedParameterOrExistingIndex.CreateAdded("int", "x", isRequired: false, defaultValue: "3", isCallsiteOmitted: true),
new AddedParameterOrExistingIndex(2)};
var updatedCode = @"
[Some(1, 2, y: 4)]
class SomeAttribute : System.Attribute
{
public SomeAttribute(int a, int b, int x = 3, int y = 4)
{
}
}";
await TestChangeSignatureViaCommandAsync(LanguageNames.CSharp, markup, updatedSignature: permutation, expectedUpdatedInvocationDocumentCode: updatedCode);
}
[WpfFact, Trait(Traits.Feature, Traits.Features.ChangeSignature)]
public async Task AddAndReorderExtensionMethodParametersAndArguments_StaticCall()
{
......
......@@ -811,7 +811,12 @@ protected override IEnumerable<AbstractFormattingRule> GetFormattingRules(Docume
protected override SyntaxNode AddNameToArgument(SyntaxNode newArgument, string name)
{
return ((ArgumentSyntax)newArgument).WithNameColon(NameColon(name));
return newArgument switch
{
ArgumentSyntax a => a.WithNameColon(NameColon(name)),
AttributeArgumentSyntax a => a.WithNameColon(NameColon(name)),
_ => throw ExceptionUtilities.UnexpectedValue(newArgument.Kind())
};
}
protected override SyntaxNode CreateExplicitParamsArrayFromIndividualArguments(SeparatedSyntaxList<SyntaxNode> newArguments, int indexInExistingList, IParameterSymbol parameterSymbol)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册