Refine.Generators 0.0.8

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

// Install Refine.Generators as a Cake Tool
#tool nuget:?package=Refine.Generators&version=0.0.8                

Refine

Refine is a source generator to help you design data types.

Quick Start

1. Add the NuGet

dotnet add package Refine 
dotnet add package Refine.Generators

2. Decorate Your Class

Add the RefinedTypeAttribute to a class and mark it as partial.

using Refine;

[RefinedType(typeof(string))]
public partial class FullName;

3. Transform and/or Validate

using Refine;

[RefinedType(typeof(string))]
public partial class FullName
{
    private static string Transform(string value) =>
        value?.Trim() ?? "";
        
    private static bool TryValidate(string value) =>
        !string.IsNullOrEmpty(value);
}

4. Instantiate

string raw = "\tJames T. Kirk ";
Console.WriteLine($"Raw:     '{raw}'");

var refined = FullName.Create("\tJames T. Kirk  ");
Console.WriteLine($"Refined: '{refined.Value}'");
Raw:     '      James T. Kirk '
Refined: 'James T. Kirk'

5. Invalid States Are Unrepresentable

var bad = FullName.Create(Environment.NewLine);

throws ArgumentException: Validation failed for the provided value.

Deeper Dive

  1. Look at the samples
  2. Inspect the generated code
    • add <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> to your csproj
    • generated code will be under obj/Debug/net8.0/generated/
  3. More coming...
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
0.0.9-preview.0.5 0 1/21/2025
0.0.8 34 1/19/2025
0.0.7 30 1/19/2025
0.0.6 27 1/19/2025
0.0.5 29 1/18/2025
0.0.4 34 1/12/2025
0.0.1 31 1/12/2025