ℹ This is for v0.6 of RecordGenerator.
Documentation available at amis92.github.io/RecordGenerator (or in docs folder).
C# Record Generator makes creating immutable record types a breeze! Just adorn your data class with [Record]
attribute
and keep your code clean and simple. The backing code is generated on build-time, including IntelliSense support
(just save the file, Visual Studio will make a build in background).
Installation, usage, examples and all other docs available at amis92.github.io/RecordGenerator
using System;
using Amadevus.RecordGenerator;
namespace QuickDemo
{
[Record(Features.Default | Features.Equality)]
public sealed partial class Contact
{
public int Id { get; }
public string Name { get; }
public string Email { get; }
public DateTime? Birthday { get; }
}
public static class Program
{
public static void Main()
{
var adam = new Contact.Builder
{
Id = 1,
Name = "Adam Demo",
Email = "foo@bar.com"
}.ToImmutable();
var adamWithBday = adam.WithBirthday(DateTime.UtcNow);
Console.WriteLine("Pretty display: " + adamWithBday);
// Pretty display: { Id = 1, Name = Adam Demo, Email = foo@bar.com, Birthday = 06.01.2020 23:17:06 }
Console.WriteLine("Check equality: " + adam.Equals(adamWithBday));
// Check equality: False
Console.WriteLine("Check equality: " + adam.Equals(new Contact(1, "Adam Demo", "foo@bar.com", null)));
// Check equality: True
}
}
}
The above is taken from QuickDemo sample
To build the solution, .NET Core SDK v3.1.100 is required, as specified in global.json
.
Amadevus.RecordGenerator
wouldn't work if not for @AArnott AArnott's CodeGeneration.Roslyn.
Analyzers in Amadevus.RecordGenerator.Analyzers
were inspired by xUnit.net's analyzers.
All contributions are welcome, as well as critique. If you have any issues, problems or suggestions - please open an issue.
Visual Studio logo ™ Microsoft Corporation, used without permission.
RecordGenerator logo (on top) © 2017 Amadeusz Sadowski, all rights reserved.