Bnaya.TypePatterns.Generators.Abstractions
1.0.4
dotnet add package Bnaya.TypePatterns.Generators.Abstractions --version 1.0.4
NuGet\Install-Package Bnaya.TypePatterns.Generators.Abstractions -Version 1.0.4
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="Bnaya.TypePatterns.Generators.Abstractions" Version="1.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Bnaya.TypePatterns.Generators.Abstractions --version 1.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Bnaya.TypePatterns.Generators.Abstractions, 1.0.4"
#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 Bnaya.TypePatterns.Generators.Abstractions as a Cake Addin #addin nuget:?package=Bnaya.TypePatterns.Generators.Abstractions&version=1.0.4 // Install Bnaya.TypePatterns.Generators.Abstractions as a Cake Tool #tool nuget:?package=Bnaya.TypePatterns.Generators.Abstractions&version=1.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
TypePatterns Generators
This package show how to mimic Typescropt's Utility Types using Source Code Generator.
[Partial]
public readonly partial record struct RecStruct(int? Value, string Name)
{
public required int Quantity { get; init; }
public string Tag { get; init; } = string.Empty;
public string Description => $"{Name}: {Quantity}";
}
Will generate:
public record struct RecStructNullable
{
public int? Value{ get; init; }
public string? Name{ get; init; }
public int? Quantity{ get; init; }
public string? Tag{ get; init; }
}
And
partial record struct RecStruct
{
public static RecStruct operator +(RecStruct a, RecStructNullable b)
{
var result = a with {
Value = b.Value ?? a.Value,
Name = b.Name ?? a.Name,
Quantity = b.Quantity ?? a.Quantity,
Tag = b.Tag ?? a.Tag,
};
return result;
}
}
As result, the following test, pass.
[Fact]
public void RecStruct1_Test()
{
var r = new RecStruct1 { Value = -150, Name = "Be'ery 😞", Quantity = -150 };
var rn = new RecStruct1Nullable { Value = -160 };
var r2 = r + rn;
Assert.Equal(r.Name, r2.Name);
Assert.Equal(r.Quantity, r2.Quantity);
Assert.Equal(rn.Value, r2.Value);
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net7.0
- System.Collections.Immutable (>= 7.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.