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.
paket add Refine.Generators --version 0.0.10
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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.
// Install Refine.Generators as a Cake Addin #addin nuget:?package=Refine.Generators&version=0.0.10 // Install Refine.Generators as a Cake Tool #tool nuget:?package=Refine.Generators&version=0.0.10
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Refine
Refine is a source generator to help you design data types.
- avoid primitive obsession
- "make illegal states unrepresentable" - Yaron Minsky
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
- Look at the samples
- Inspect the generated code
- add
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
to your csproj - generated code will be under
obj/Debug/net8.0/generated/
- add
- 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 | 28 | 2/1/2025 |
0.0.9-preview.0.6 | 24 | 2/1/2025 |
0.0.9-preview.0.5 | 41 | 1/21/2025 |
0.0.8 | 94 | 1/19/2025 |
0.0.7 | 57 | 1/19/2025 |
0.0.6 | 63 | 1/19/2025 |
0.0.5 | 56 | 1/18/2025 |
0.0.4 | 38 | 1/12/2025 |
0.0.1 | 35 | 1/12/2025 |