Skip to content

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

License

Notifications You must be signed in to change notification settings

ufcpp/RecordConstructorGenerator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 

Repository files navigation

RecordConstructorGenerator

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

This inlcudes VSIX and NuGet packages of an analyzer created by using .NET Compiler Platform (Roslyn).

Usage

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

Sample

original source:

    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;
    }

the generated result:

    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;
        }
    }

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •