RichEntity 1.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package RichEntity --version 1.0.3                
NuGet\Install-Package RichEntity -Version 1.0.3                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RichEntity" Version="1.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RichEntity --version 1.0.3                
#r "nuget: RichEntity, 1.0.3"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install RichEntity as a Cake Addin
#addin nuget:?package=RichEntity&version=1.0.3

// Install RichEntity as a Cake Tool
#tool nuget:?package=RichEntity&version=1.0.3                

RichEntity Nuget

A library for reducing boilerplate when defining entities. It is using Roslyn's Source Generators to generate the code that is needed for entity definition.

Usage

To generate an entity, you will need to add an IEntity<TIdentifier> to base list of your entity class.

public partial class Sample : IEntity<int> { }

The library will generate this code in the background.

public partial class Sample : IEquatable<Sample>
{
    public Int32 Id { get; protected init; }

    protected Sample(Int32 id)
    {
        Id = id;
    }

#nullable enable
    public bool Equals(Sample? other)
#nullable restore
    {
        return other?.Id.Equals(Id) ?? false;
    }

#nullable enable
    public override bool Equals(object? other)
#nullable restore
    {
        return Equals(other as Sample);
    }

    public override int GetHashCode() => Id.GetHashCode();
}

You can customize generated code via attributes.

ConfigureConstructorsAttribute

To configure generated entity constructors decorate type with ConfigureConstructorsAttribute.

Settings:
  • ParametrizedConstructorAccessibility
    Accessibility of parameterized constructor (Entity(TIdentity id)).
[ConfigureConstructors(ParametrizedConstructorAccessibility = Accessibility.Public)]
public partial class Sample : IEntity<int> { }
public partial class Sample : IEquatable<Sample>
{
    public Int32 Id { get; protected init; }

    public Sample(Int32 id)
    {
        Id = id;
    }

#nullable enable
    public bool Equals(Sample? other)
#nullable restore
    {
        return other?.Id.Equals(Id) ?? false;
    }

#nullable enable
    public override bool Equals(object? other)
#nullable restore
    {
        return Equals(other as Sample);
    }

    public override int GetHashCode() => Id.GetHashCode();
}

ConfigureIdAttribute

To configure generated identifier decorate type with ConfigureIdAttribute.

Settings:
  • SetterAccessibility
    Accessibility of Id property setter.
  • SetterType
    Type of Id property setter (set / init).
[ConfigureId(SetterAccessibility = Accessibility.Internal, SetterType = SetterType.Set)]
public partial class Sample : IEntity<int> { }
public partial class Sample : IEquatable<Sample>
{
    public Int32 Id { get; internal set; }

    protected Sample(Int32 id)
    {
        Id = id;
    }

#nullable enable
    public bool Equals(Sample? other)
#nullable restore
    {
        return other?.Id.Equals(Id) ?? false;
    }

#nullable enable
    public override bool Equals(object? other)
#nullable restore
    {
        return Equals(other as Sample);
    }

    public override int GetHashCode() => Id.GetHashCode();
}
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.3 79 10/14/2024
1.1.2 2,983 12/25/2022
1.1.1 3,080 8/26/2022
1.1.0 2,582 7/10/2022
1.0.3 1,655 7/9/2022
1.0.2 1,636 6/20/2022
1.0.1 1,676 6/20/2022
1.0.0 1,705 6/20/2022

Fixed warnings for parameterized constructors that are not initializing all properties.