-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Labels
Area-IDEBugIDE-CodeStyleBuilt-in analyzers, fixes, and refactoringsBuilt-in analyzers, fixes, and refactorings
Milestone
Description
Version Used:
Visual Studio 2019 Preview - Version 16.7.0 Preview 3.0
Steps to Reproduce:
- Create a console app with the following code.
using System;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
var point = (X: 3, Y: 4);
Console.WriteLine(point.X);
Console.WriteLine(point.Y);
}
}
}
- Select the valuetuple (X:3, Y:4) and active the 'Convert to struct' refactoring
- The constructor call will look like var point = new NewStruct(X: 3, Y: 4); The named arguments are in uppercase and should be lowercase.
As you can see you get a compiler error (red squigly line) in the preview of the refactoring.

Expected Behavior:
I expected lower case argument names: var point = new NewStruct(x: 3, y: 4);.
The following code should have been generated
using System;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
var point = new NewStruct(x: 3, y: 4);
Console.WriteLine(point.X);
Console.WriteLine(point.Y);
}
}
internal struct NewStruct {
public int X;
public int Y;
public NewStruct(int x, int y) {
X = x;
Y = y;
}
public override bool Equals(object obj) {
return obj is NewStruct other &&
X == other.X &&
Y == other.Y;
}
public override int GetHashCode() {
return HashCode.Combine(X, Y);
}
public void Deconstruct(out int x, out int y) {
x = X;
y = Y;
}
public static implicit operator (int X, int Y)(NewStruct value) {
return (value.X, value.Y);
}
public static implicit operator NewStruct((int X, int Y) value) {
return new NewStruct(value.X, value.Y);
}
}
}
Actual Behavior:
The following code is generated
using System;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
var point = new NewStruct(X: 3, Y: 4);
Console.WriteLine(point.X);
Console.WriteLine(point.Y);
}
}
internal struct NewStruct {
public int X;
public int Y;
public NewStruct(int x, int y) {
X = x;
Y = y;
}
public override bool Equals(object obj) {
return obj is NewStruct other &&
X == other.X &&
Y == other.Y;
}
public override int GetHashCode() {
return HashCode.Combine(X, Y);
}
public void Deconstruct(out int x, out int y) {
x = X;
y = Y;
}
public static implicit operator (int X, int Y)(NewStruct value) {
return (value.X, value.Y);
}
public static implicit operator NewStruct((int X, int Y) value) {
return new NewStruct(value.X, value.Y);
}
}
}
'''
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Area-IDEBugIDE-CodeStyleBuilt-in analyzers, fixes, and refactoringsBuilt-in analyzers, fixes, and refactorings