Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A shortcut to convert classes into records in c#

If I have the following class:

public class Foo
{
    public string Code { get; set; }
    public string Description { get; set; }
    public DateTime? EffectiveDate { get; set; }
}

and I want to quickly convert it to a record type:

public record Foo(string Code, string Description, DateTime? EffectiveDate);

Is there a way to do that quickly? the built-in quick actions menu in VS19 doesn't seem to offer this.


2 Answers

dotnet developers are working on that according to this issue classtorecode

like image 86
amir elkaser Avatar answered Sep 16 '25 12:09

amir elkaser


You can try "Convert to positional record" in VS 2022 after clicking the class and then the screwdriver on the left.

like image 41
eyelesscactus54 Avatar answered Sep 16 '25 12:09

eyelesscactus54