Tedd.ReadOnlyStructGenerator 1.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package Tedd.ReadOnlyStructGenerator --version 1.0.3                
NuGet\Install-Package Tedd.ReadOnlyStructGenerator -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="Tedd.ReadOnlyStructGenerator" Version="1.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Tedd.ReadOnlyStructGenerator --version 1.0.3                
#r "nuget: Tedd.ReadOnlyStructGenerator, 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 Tedd.ReadOnlyStructGenerator as a Cake Addin
#addin nuget:?package=Tedd.ReadOnlyStructGenerator&version=1.0.3

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

Tedd.ReadOnlyStructGenerator

.NET Source Generator for duplicating structs to read-only copies.

Adding [GenerateReadOnlyStruct] to a struct like this

[GenerateReadOnlyStruct]
public struct Test
{
    public float X;
    public float Y;
    public float Z;
}

will inject this code into your project

public readonly struct ReadOnlyTest
{
    public readonly float X;
    public readonly float Y;
    public readonly float Z;
    
    public ReadOnlyTest(float x, float y, float z)
    {
        this.X = x;
        this.Y = y;
        this.Z = z;
    }

    public ReadOnlyTest(Test value)
    {
        X = value.X;
        Y = value.Y;
        Z = value.Z;
    }
}

[GenerateReadOnlyStruct] takes two boolean parameters:

  • GenerateConstructor
  • GenerateCopyConstructor

This allows you to disable constructor generation, in case you already have that implemented.

[GenerateReadOnlyStruct(false, false)]
public struct Test
{
    public float X;
    public float Y;
    public float Z;

    public Test(float x, float y, float z)
    {
        this.X = x;
        this.Y = y;
        this.Z = z;
    }
}

will inject this code into your project

public readonly struct ReadOnlyTest
{
    public readonly float X;
    public readonly float Y;
    public readonly float Z;

    public ReadOnlyTest(float x, float y, float z)
    {
        this.X = x;
        this.Y = y;
        this.Z = z;
    }
}
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • No dependencies.

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.0.6 1,036 12/30/2022
1.0.5 1,016 12/30/2022
1.0.4 1,059 12/28/2022
1.0.3 1,083 12/27/2022
1.0.1 1,132 12/27/2022
1.0.0 944 12/26/2022

Skip readonly on const keyword