Refine.Generators 0.0.10

dotnet add package Refine.Generators --version 0.0.10
                    
NuGet\Install-Package Refine.Generators -Version 0.0.10
                    
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.10" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Refine.Generators" Version="0.0.10" />
                    
Directory.Packages.props
<PackageReference Include="Refine.Generators" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Refine.Generators --version 0.0.10
                    
#r "nuget: Refine.Generators, 0.0.10"
                    
#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.
#addin nuget:?package=Refine.Generators&version=0.0.10
                    
Install as a Cake Addin
#tool nuget:?package=Refine.Generators&version=0.0.10
                    
Install as a Cake Tool

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(raw);
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.10 114 2/1/2025
0.0.9-preview.0.6 64 2/1/2025
0.0.9-preview.0.5 76 1/21/2025
0.0.8 121 1/19/2025
0.0.7 88 1/19/2025
0.0.6 90 1/19/2025
0.0.5 83 1/18/2025
0.0.4 76 1/12/2025
0.0.1 69 1/12/2025