Skip to content
| Marketplace
Sign in
Visual Studio>Tools>Record constructor generator
Record constructor generator

Record constructor generator

iwanaga

|
3,367 installs
| (5) | Free
Code Fix for a record (immutable class/struct) constructor generated from get-only properties.
Download

Code Fix for a record (immutabl class/struct) constructor generated from get-only properties.

This VSIX inlcudes an analyzer created by using .NET Compiler Platform.

Requirement

Requires Visual Studio 2015 or later.

NuGet Package

You can also download the analyzer from NuGet, RecordConstructorGenerator(http://www.nuget.org/packages/RecordConstructorGenerator/)

  • PM> Install-Package RecordConstructorGenerator

Usage

  • Insert a get-only auto property without a property initializer
  • Use 'Quick Action' (Lightbulb) to fix the code

 

Sample

original source:

C#
Edit|Remove
csharp
namespace RecordConstructorGenerator.Test {     class Point     {         public string Name { get; }          /// <summary>         /// x coordinate.         /// </summary>         public int X { get; }          /// <summary>         /// x coordinate.         /// </summary>         public int Y { get; }          public int A => X * Y;     } } 
namespace RecordConstructorGenerator.Test  {      class Point      {          public string Name { get; }            /// <summary>          /// x coordinate.          /// </summary>          public int X { get; }            /// <summary>          /// x coordinate.          /// </summary>          public int Y { get; }            public int A => X * Y;      }  }  
 

generated result:

C#
Edit|Remove
csharp
namespace RecordConstructorGenerator.Test {     class Point     {         public string Name { get; }          /// <summary>         /// x coordinate.         /// </summary>         public int X { get; }          /// <summary>         /// x coordinate.         /// </summary>         public int Y { get; }          public int A => X * Y;          /// <summary>Record Constructor</summary>         /// <param name="name"><see cref="Name"/></param>         /// <param name="x"><see cref="X"/></param>         /// <param name="y"><see cref="Y"/></param>         public Point(string name = default(string), int x = default(int), int y = default(int))         {             Name = name;             X = x;             Y = y;         }     } } 
namespace RecordConstructorGenerator.Test  {      class Point      {          public string Name { get; }            /// <summary>          /// x coordinate.          /// </summary>          public int X { get; }            /// <summary>          /// x coordinate.          /// </summary>          public int Y { get; }            public int A => X * Y;            /// <summary>Record Constructor</summary>          /// <param name="name"><see cref="Name"/></param>          /// <param name="x"><see cref="X"/></param>          /// <param name="y"><see cref="Y"/></param>          public Point(string name = default(string), int x = default(int), int y = default(int))          {              Name = name;              X = x;              Y = y;          }      }  }  
 
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft