Skip to content
This repository has been archived by the owner on Apr 13, 2021. It is now read-only.

danslapman/RecSharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RecSharp

RecSharp is an immutable record generator for .NET Immutable records are similiar to F#'s records or Scala's case classes, but can be used from C# safely.

Here is the sample record definition (You can found it in sample.rcs)

namespace Records {
    using System;

    record Test {
        Int32 Id;
        String Name;
		Nullable<Decimal> Amount;
    }
}

Generater class Test will have:

  • getter-only properties
  • constructor with parameters for properties initialization
  • Copy() method with optional parameters
  • IEquatable implementation
  • overrides os Equals() and GetHashCode()
  • == and != operators

External libraries can be referenced by command-line parameter or by the following syntax (which if useful for VS extension):

#ref System.Linq.dll;

Compile it with RecSharpC -i sample.rcs -o Records.dll and reference Records.dll to Your project. That's it!