Refine.Generators
0.0.8
There is a newer prerelease version of this package available.
See the version list below for details.
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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
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("\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
- 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.