C# Change signature refactoring generates wrong syntax for named arguments in attribute constructor calls
#50,940 opened on Feb 1, 2021
Repository metrics
- Stars
- (20,414 stars)
- PR merge metrics
- (Avg merge 6d 17h) (256 merged PRs in 30d)
Description
This issue has been moved from a ticket on Developer Community.
[severity:It's more difficult to complete my work] When using the "Change signature" refactoring in C# to add a new parameter to a constructor of an attribute class and requesting to inject a value using a named argument at existing call sites, the generated syntax for that argument at the call sites where the attribute is applied to a member is wrong: using the = symbol for assigning the argument value, where it should be using the : symbol.
Steps to reproduce:
- Create a new C# Console App project (.NET Framework 4.8).
- Replace the Program class in Program.cs with the following code:
class Program
{
[Foo(a: 5)]
static void Main(string[] args)
{
}
class FooAttribute : Attribute
{
public FooAttribute(int a)
{
}
}
}
- Invoke the "Change signature" refactoring on the FooAttribute constructor.
- Press the Add button.
- Fill out the dialog as follows: Type name: int, Parameter name: b, Parameter kind: Required, Value to inject at all call sites: Value 2, "Use named argument" checked
- Press the OK button.
- Press the OK button of the change signature dialog.
Expected result at the call site:
[Foo(a: 5, b: 2)]
Actual result at the call site:
[Foo(a: 5, b = 2)]
Original Comments
Feedback Bot on 1/31/2021, 07:39 PM:
Original Solutions
(no solutions)