CodoMetis.TypeKit.Generators
2.4.0-preview.3
Prefix Reserved
dotnet add package CodoMetis.TypeKit.Generators --version 2.4.0-preview.3
NuGet\Install-Package CodoMetis.TypeKit.Generators -Version 2.4.0-preview.3
<PackageReference Include="CodoMetis.TypeKit.Generators" Version="2.4.0-preview.3" />
<PackageVersion Include="CodoMetis.TypeKit.Generators" Version="2.4.0-preview.3" />
<PackageReference Include="CodoMetis.TypeKit.Generators" />
paket add CodoMetis.TypeKit.Generators --version 2.4.0-preview.3
#r "nuget: CodoMetis.TypeKit.Generators, 2.4.0-preview.3"
#:package CodoMetis.TypeKit.Generators@2.4.0-preview.3
#addin nuget:?package=CodoMetis.TypeKit.Generators&version=2.4.0-preview.3&prerelease
#tool nuget:?package=CodoMetis.TypeKit.Generators&version=2.4.0-preview.3&prerelease
CodoMetis.TypeKit.Generators
Declare a value object in one line, and get a complete type at compile time. This package generates
value objects and closed sets (smart enums) for
CodoMetis.TypeKit. It is built on
Metalama, a framework that generates C# code at compile time from
templates written in C#. Each value object comes with its JSON converter, parsing,
formatting, comparison, type converter and query helpers, and every one of them runs the one
Create you wrote.
dotnet add package CodoMetis.TypeKit.Generators
Reference it in the project that declares your value objects. Projects that reference that one,
directly or further down, get the generators too, without referencing the package themselves.
Metalama.Framework comes along with it, because the fabric that applies the generators runs in
every one of those projects. You need no Metalama license key, there or here: the generators build on
Metalama's Open Source edition.
This page is the reference for the package. For a guide to designing value objects, read Value objects. To see how TypeKit compares with Vogen, Thinktecture.Runtime.Extensions and StronglyTypedId, and when one of them is the better choice, read How it compares.
Built with Metalama
This package exists in this form because of Metalama. A transitive fabric finds every type that implements a TypeKit interface, in the project that references this package and in every project that references that one. So you declare a value object by its interface and nothing else.
Templates write the generated members as ordinary C#, which you can read (see "Reading the generated code"). A declaration that can't be generated fails the build with its name on it (see "Build errors"), instead of compiling to less than it appears to. Thanks to the Metalama team.
Declare a value object
using CodoMetis.TypeKit;
using CodoMetis.TypeKit.ValueObjects;
public readonly partial record struct OrderId : IValue<Guid>;
public readonly partial record struct Quantity : IValue<int>;
public enum EmailFault { Blank, NoAt, TooLong }
public readonly partial record struct Email : IValidatedValue<Email, string, EmailFault>
{
public static Result<Email, EmailFault> Create(string value)
{
if (string.IsNullOrWhiteSpace(value)) return Result.Error(EmailFault.Blank);
var trimmed = value.Trim();
if (!trimmed.Contains('@')) return Result.Error(EmailFault.NoAt);
if (trimmed.Length > 254) return Result.Error(EmailFault.TooLong);
return new Email(trimmed); // the private constructor is generated
}
}
A value object is a readonly partial record struct, or a sealed partial record class when it has
to be a reference type. There are two interfaces:
IValue<T>wraps anyT.IValidatedValue<TSelf, T, TFault>addsCreate, the one method you write. Every way a value gets created runs it.
You don't have to type Create out. Declare the interface first. The build then fails because
Create is missing (CS0535), and your editor offers a fix for that error: Add Create. It writes
a Create that accepts every value, ready for your rules:
public enum NameFault { Blank, TooLong }
public readonly partial record struct Name : IValidatedValue<Name, string, NameFault>
{
public static Result<Name, NameFault> Create(string value)
{
// Add your rules: if (...) return Result.Error(NameFault.Blank);
return new Name(value);
}
}
A validated value object has no From. You create one with Create, TryFrom or FromKnownGood,
so nothing harmless-looking throws on input. The one factory that throws says in its name that you
vouch for the value, and its exception names the call site, never the value.
The error Create returns (TypeKit calls it a fault) is what every rejection reports: in that
exception, in the JSON converter's JsonException, and in Parse's FormatException.
<details> <summary>What the generators write for <code>Email</code>, trimmed</summary>
Every factory below calls the Create you wrote:
public readonly partial record struct Email : IValidatedValue<Email, string, EmailFault>, IValueObject<Email, string>
{
private readonly string _value;
private Email(string value)
{
_value = value;
}
public string Value
{
get { return _value; }
}
public static Option<Email> TryFrom(string value)
{
return Result.ToOption(Email.Create(value));
}
public static Email FromKnownGood(string value, [CallerArgumentExpression("value")] string? source = null)
{
return GeneratedFactories.OrInvalidOperationException(Email.Create(value), source);
}
public Result<Email, EmailFault> Revalidate()
{
return Email.Create(Value);
}
// Also: Parse and TryParse, formatting, comparison, a JSON converter and a type converter.
}
</details>
You can declare a value object inside another type. Order.Id is generated like any other. Its
companion class is OrderIdExtensions, named after the whole nesting chain, so Order.Id and
Customer.Id don't collide.
var id = OrderId.New(); // a version 7 Guid
var quantity = Quantity.From(3);
Result<Email, EmailFault> created = Email.Create(input); // says what to fix
Option<Email> maybe = Email.TryFrom(input); // is it valid?
Email known = Email.FromKnownGood("ops@example.com"); // yours to guarantee; throws otherwise
int three = quantity.Value; // 3
bool same = quantity == Quantity.From(3); // true, value equality
string text = quantity.ToString(); // "3"
What you can wrap
Any non-generic class, struct or enum, with the exceptions listed under CMTK1005. The generated members follow what the underlying type can do:
- Parsing where it can be parsed.
- Formatting where it formats.
- Comparison where it's comparable.
Numbers, bool, char, string, Guid, DateTime, DateTimeOffset, DateOnly, TimeOnly and
enums have all of it. A Uri has no ordering. Neither do NodaTime's OffsetDateTime,
ZonedDateTime, Period and Interval, and Interval also has no type converter to parse through.
An enum parses as Enum.TryParse does, case-sensitively: a name, a comma-separated list of names, or
a number, which doesn't have to name a member.
A generic underlying type, a tuple included, fails the build (CMTK1005). A List<T> or an
ImmutableArray<T> compares by reference, so the value object wouldn't have value equality. Wrap a
type of your own that does.
Unions and closed classes
On .NET 11 you can wrap a C# 15 union, such as union Pet(Cat, Dog), or a closed class:
- A union is written to JSON as the union writes itself, byte for byte, and read back the same way. The value object compares and prints as the union does.
- A union has no
Parse. C# doesn't say how text becomes one case or another, so the value object gets no parsing, even when one of the cases is astring. Fromrejects a union that holds no case, itsdefault, as it rejects a null. A JSON read rejects one too, when a converter you register for the union hands it back. Declare the property asPetId?where the value can be absent.- A closed class is an abstract class to the serializer. With
[JsonPolymorphic(InferClosedTypePolymorphism = true)]on it, the value object writes the subtype with its discriminator and reads it back. Without the attribute, it's written by its declared members and can't be read back.
The union or the closed class can't be a value object itself. A union that declares a marker fails the
build (CMTK1005), and so does a closed class (CMTK1022). Wrap it in a value object of its own instead.
What is generated
| Member | For | Notes |
|---|---|---|
Value, a private constructor, value equality |
every value object | The record's equality, over the underlying value. Declare no constructor of your own, not even a parameter list (CMTK1009). |
From(T) |
IValue<T> |
Rejects null for a reference type. |
TryFrom(T), FromKnownGood(T) |
IValidatedValue |
Both built from your Create. FromKnownGood throws with the caller's expression in the message, never the value. Declare either one yourself and it isn't generated (see "Write your own members" below). |
Revalidate() |
IValidatedValue |
Runs Create on the value an instance holds. It answers: which values read back without validation (a column, a stored document) would today's rules reject? Returns what Create returns, normalisation included. |
[JsonConverter] with a nested converter |
every value object | Reads and writes the underlying value exactly as the serializer does, also as a dictionary key. A struct value object rejects a JSON null (see JSON below). |
IParsable |
when the underlying type can be parsed | A Uri parses relative or absolute, as JSON reads it. A NodaTime type parses through its type converter. |
ISpanParsable, IUtf8SpanParsable |
where the underlying type has them | Each one reads and rejects the same text as Parse. A string has ISpanParsable only. A Uri, an enum and a NodaTime type have neither. |
IFormattable, ISpanFormattable, IUtf8SpanFormattable, ToString() |
every value object, unless you write ToString() |
Invariant. A ToString() you write is kept, and then none of the formatting interfaces is generated, so interpolation and string.Format use yours too. |
IEqualityOperators<TSelf, TSelf, bool> |
every value object | The generic-math form of ==/!=, so a value object satisfies that constraint. |
IComparable<TSelf>, IComparable, IComparisonOperators<TSelf, TSelf, bool>, < > <= >= |
when the underlying type is comparable | Strings compare ordinally, so ordering agrees with equality. |
MinValue, MaxValue, IMinMaxValue<TSelf> |
IValue<T> over a type whose own static MinValue/MaxValue are of that type |
Never for a validated value object. |
+, -, *, /, %, unary - and +, and their checked forms |
IValue<T> that declares IAdditionOperators, ISubtractionOperators, IMultiplyOperators, IDivisionOperators, IModulusOperators, IUnaryNegationOperators or IUnaryPlusOperators, where T implements the same interface with T in place of the value object |
Only what you declare, and never for a validated value object. Each operator calls T's, so the result, the overflow and the checked context are T's. A null operand of a record class throws ArgumentNullException. An operator you write is kept (see "Write your own members" below). |
[TypeConverter] with a nested converter |
when parsing is generated | MVC model binding and the reflection-based configuration binder use it. The configuration binding source generator, which PublishAot and PublishTrimmed turn on, doesn't bind value objects and leaves them default. Bind the underlying type there. |
IConvertible |
when the underlying type is convertible | Explicit, so Convert.ToInt64(quantity) and Convert.ChangeType(quantity, typeof(Quantity)) work. |
{TSelf}Extensions.GetValue() and ValueOrNull() |
every value object an extension class can reach: internal for an internal or protected internal one, and none for a private, protected or private protected nested one |
For EF Core queries, where they translate to the column. |
IValueObjectMaterializer<TSelf, T> |
every value object | Explicit, so it's invisible on the type. Rebuilds an instance without validation, for the EF Core package. |
Every generated way of creating a validated value object goes through Create. Two paths skip it,
both for values your application wrote itself:
- The explicit materializer, which the EF Core package reads a column through.
StoredJsonConverterFactory, registered only on the options that read your application's own JSON.
Inside the type, your own members can reach the private constructor, which applies no rules, because
Create needs it. Call it from Create only. For another way of creating a value, write a static
method that calls From or Create.
Good to know
default(Email)isn't a way to create one. The analyzer rejects it (CMTK0001). But an array slot, or a JSON document without the property, can still produce it (CMTK0005, and "A missing property" below). ItsValueis the underlying type'sdefault:Guid.Emptyfor anOrderId, andnullfor anEmaildespite itsstringtype.
Write your own members
A value object may declare its own TryFrom, FromKnownGood, Revalidate, CompareTo(TSelf) and
ToString(). Each one is kept, and whatever depends on it is built from it.
Declare them on the value object itself. A TryFrom, Revalidate or CompareTo in a base record fails
the build (CMTK1011, or CMTK1008 for CompareTo), because it would stand in for the generated member
without a word. A base record's sealed ToString() is the one exception, as described below.
An arithmetic operator you write is kept as well, and so is an explicit implementation of its
interface, yours, a base record's or one an interface of yours supplies. Its checked form is then yours too: TypeKit generates neither
form of that operator, and generates the ones you didn't write. A checked operator you write needs the
plain one beside it, as C# requires (CS9025), and TypeKit doesn't write that one for you either. Code
that wrote these operators by hand before 2.4 builds unchanged. A database can't run an operator you
write, so an EF Core query that uses one is rejected, naming the value object
(CodoMetis.TypeKit.EntityFrameworkCore).
The generated ones carry [TranslatedAsWrappedArithmetic], which tells the query they are the
underlying type's arithmetic. C# allows one operator per pair of operand types, so of two interfaces
that ask for the same operator, such as IDivisionOperators<Money, Money, Money> and
IDivisionOperators<Money, Money, decimal>, only the first is generated, and the second fails the build
(CS0738) until you implement it explicitly.
Writing any other generated member or attribute by hand fails the build, naming it (CMTK1011). That covers:
- A plain value object's members:
From,Value,ParseandTryParse,MinValue/MaxValue. - The attributes:
[JsonConverter]and[TypeConverter]. - The contracts the generators implement:
IValueObject<TSelf, T>,IValueObjectMaterializer<TSelf, T>,IPlainValueObject<TSelf, T>, andIConvertiblewhere they generate it. That holds whether you declare one directly, through an interface of your own or in a base record. To constrain generic code, useIValueObject<TSelf, T>itself, which every value object implements. - An explicit implementation of a member of an interface they implement, such as
IParsable<TSelf>.ParseorIFormattable.ToString. On the value object or a base record, every caller through the interface would reach it rather than the generated member, and a genericT.Parsewould skipCreate. - The same explicit implementation in an interface the value object implements. The generated member would replace it, so it would never run. The error names the interface, in your project or another.
- Any of these members in a base record, public or explicit, in your project or another. A base's
MaxValuewould stand in for the generated one, and generic code callingT.MaxValuewould reach it. The error names the base. A base'sprivatemember is fine: the value object can't see it, so it stands in for nothing.
An overload of a generated member is yours, and the generated one sits beside it. C# tells two methods
apart by their type parameters and by whether a parameter is ref, in or out, so a
Parse<TFormat>(string, IFormatProvider?), a From(in int value) or a TryParse whose last parameter
isn't out is kept, on the value object or a base record. A ref or in where the generated member has
out is the same method to C#, as a different nullability is, so it fails the build like the member itself.
The same goes for the members you may write: a generic ToString<TFormat>() or a CompareTo(in TSelf) isn't
the one that's kept, so the generated ToString() and ordering are still there.
Two explicit implementations in an interface are fine, because a value object loses nothing by
replacing them. A record's own == and != replace an interface's, generated or not. And .NET's
INumberBase<TSelf> formats and parses UTF-8 through the UTF-16 members, which every .NET number
replaces with its own, as the generated members do.
Declare Create once, public static, and never as an explicit interface implementation. The
generated code can't call an explicit one. And beside a public one, generic code calling T.Create
would reach the explicit one's rules, not the ones every generated way of creating a value runs.
The same goes for a Create your value object inherits from a base record in another project. If
the value object only gets the marker through that base, generic code calling T.Create reaches the
base's Create, while everything generated calls yours, and the build fails (CMTK1011). Declare the
marker on the value object too, and your Create is the one both reach.
An overload the generated call can't mean, such as Create(int) on a value object over a string, is
yours to add. One it would mean instead of the base's fails the build the same way: Create(object), a
generic Create<T>(T), or a Create(string, int count = 0).
To change what a value object prints, declare ToString(). A record's
PrintMembers(StringBuilder) without it fails the build (CMTK1011), since the generated ToString()
prints the underlying value and never calls it.
Base records
What a base record declares counts as the value object's own:
- A
sealedToString()on the base is kept, since C# keeps it in every derived record. - A
ToString()that isn't sealed fails the build (CMTK1011), because the generatedToString()would replace it. DeclareToString()in the value object, or seal the base's. - Its
PrintMembers, its explicit implementations of the interfaces the generators implement, and anIConvertibleon it are rejected as they are on the value object.
Equality
Equality is the underlying value's, like the ordering, the JSON and the column. So a hand-written
Equals(TSelf), GetHashCode(), IEquatable<TSelf>.Equals, or operator == or != between two of
the type, fails the build (CMTK1011). It would make values equal that sort apart. So does an Equals
you write for one of its base records' types, such as Equals(DeepBase?): a HashSet<DeepBase> would
compare by it while == compares the underlying value.
To make values equal that differ only in form, such as "abc" and "ABC", normalise them in Create.
Equal values then hold the same underlying value. A plain value object becomes an IValidatedValue
for that.
Over a base record, the generated Equals(TSelf) and GetHashCode() compare the underlying value
alone, and never call the base's. So a hand-written Equals(TBase), GetHashCode() or
IEquatable<TBase>.Equals on a base record isn't used, and a warning names it (CMTK1023). The value
object implements each base's IEquatable<TBase> again (IReimplementedEquatable<TBase>), so a
collection of the base compares it the way the value object does.
Obsolete value objects
An [Obsolete] on a value object, or on a type it's nested in, is copied to its
{TSelf}Extensions class, which names the value object outside it. Without the copy, with
error: true, that use failed the build.
One value, nothing else
A value object holds its underlying value and nothing else. Its JSON, parsing, type converter and column carry that value alone, while a record's equality compares every field. So any other instance state would be lost on a round trip, or make equal values unequal.
An instance field, an auto-property, a required member or a field-like event fails the build
(CMTK1012), whether declared or inherited from a base record. A property computed from Value
without a backing field is fine, and so is anything static or const.
A base record from another assembly is seen without its private fields, and a writable property of it counts as state. What a private field of it holds takes no part in the value object's equality, and is lost on a round trip like anything else beside the value.
A value that must not be printed
public sealed partial record ApiKey : IValue<string>
{
public override string ToString() => "ApiKey(***)";
}
For a value object over a secret, declare ToString(). Then no formatting interface is generated, so
these all print what your ToString() says: interpolation, string.Format, Convert.ToString, a
record that holds it, and every Microsoft.Extensions.Logging path, [LogProperties] included.
Good to know
- Some things still carry the value, because they're conversions and not display: its JSON, the
type converter and the database column. The debugger too, which shows
ToString()but expandsValue. - Serilog reads the public
Valuewhere it destructures ({@Key}, or a record holding one), pastToString(). CodoMetis.TypeKit.Serilog logs every value object as what it prints instead. - Microsoft.Extensions.Compliance: classify the logging method's parameter. A
DataClassificationAttributeon the value object's type makes the logging generator report LOGGEN035 and generate nothing for the method.
Closed sets
An enum names its members and nothing else:
- A
switchover one is never proven complete. C# only warns about a missing discard. - A member carries no data.
- The names are integers on the wire, unless a converter says otherwise.
A closed set fixes all three. It's a sealed class whose every instance is a named member, declared as
a public static readonly field. Where the members carry data, it's constant data passed through a
private constructor:
public sealed partial class OrderStatus : IClosedSet<OrderStatus>
{
public static readonly OrderStatus Open = new();
public static readonly OrderStatus Shipped = new();
public static readonly OrderStatus Cancelled = new();
}
public sealed partial class Tier : IClosedSet<Tier>
{
public static readonly Tier Basic = new(1, null);
public static readonly Tier Premium = new(2, "Priority support.");
private Tier(int rank, string? perk) { Rank = rank; Perk = perk; }
public int Rank { get; }
public string? Perk { get; }
}
var label = status.Match(open: () => "Open", shipped: () => "On its way", cancelled: () => "Cancelled"); // every member, or it does not compile
var names = OrderStatus.All.Select(s => s.Name); // Open Shipped Cancelled
var same = OrderStatus.Parse("Shipped") == OrderStatus.Shipped; // True, members are singletons
var json = JsonSerializer.Serialize(Tier.Premium); // "Premium"
The generators add:
Name, from the field's name, andQualifiedName(OrderStatus.Open).All, in declaration order and read-only.Match, with one required delegate per member, named after it.TryParseandParseby name, each ordinal, or ignoring case when you ask.ToString().- A JSON converter that writes the name and reads the member itself back.
- A private parameterless constructor, where the type declares none.
Members are singletons, so equality is reference equality. A member added later fails every Match
until it's handled.
<details> <summary>What the generators write for <code>OrderStatus</code>, trimmed</summary>
public sealed partial class OrderStatus : IClosedSet<OrderStatus>, IParsable<OrderStatus>
{
private static readonly IReadOnlyList<OrderStatus> _all = null!;
private string _name = null!;
static OrderStatus()
{
OrderStatus.Open._name = "Open";
OrderStatus.Shipped._name = "Shipped";
OrderStatus.Cancelled._name = "Cancelled";
OrderStatus._all = Array.AsReadOnly(new OrderStatus[] { OrderStatus.Open, OrderStatus.Shipped, OrderStatus.Cancelled });
}
private OrderStatus() { }
public string Name
{
get { return _name ?? throw GeneratedClosedSets.NotAMember("OrderStatus"); }
}
public TResult Match<TResult>(Func<TResult> open, Func<TResult> shipped, Func<TResult> cancelled)
{
ArgumentNullException.ThrowIfNull(open, "open");
ArgumentNullException.ThrowIfNull(shipped, "shipped");
ArgumentNullException.ThrowIfNull(cancelled, "cancelled");
if (object.ReferenceEquals(this, OrderStatus.Open))
return open.Invoke();
if (object.ReferenceEquals(this, OrderStatus.Shipped))
return shipped.Invoke();
if (object.ReferenceEquals(this, OrderStatus.Cancelled))
return cancelled.Invoke();
throw GeneratedClosedSets.NotAMember("OrderStatus");
}
// Also: All, QualifiedName, Parse and TryParse, ToString and a JSON converter.
}
</details>
Matching, parsing and binding
Matcharguments must be named (CMTK0012). Every parameter ofMatchhas the same type, so an argument by position would follow the declaration order, and swap branches when two members are reordered. The analyzer's code fix names them.Matchchecks every delegate for null before it picks one.- Unknown names are rejected.
Parseand the JSON converter throw for an unknown name, with an exception naming the set, never the input. A set is a dictionary key in JSON by its name too. - Casing.
Parse(name, ignoreCase: true)andTryParse(name, ignoreCase: true, out member)accept any casing. JSON, the type converter,IParsableand a bound route or query parameter stay ordinal, since what's stored or sent is the name as it is. For a header or a query string a client typed in any casing, bind it as astringand parse it withignoreCase: true. IParsable<TSelf>is implemented explicitly, for generic code that parses throughT.Parse.- A type converter reads and writes the name. So the configuration binder, MVC, and anything else
that reads a string through
TypeDescriptorcan bind a set. The binder's source generator reads no type converter (dotnet/runtime#83599). Under it, as under Native AOT, bind the name as astringandParseit. - Nothing to register per set. The EF Core package maps a closed set to a text column of the member's name. The ASP.NET Core package describes it as a string enum of the names.
- Error sets. A set whose members are errors declares
IFaultSet<TSelf>, aFaultKindand an optional description per member. The ASP.NET Core package answers it by kind.
Rules for a closed set
- Each member is initialized with
newwhere it's declared (CMTK1019), and never written again (CMTK0013, the analyzer's). A member assigned in the static constructor would hold an instance named and listed as another. - The constructors are private (CMTK1016).
- A record fails the build (CMTK1020).
- Member names. A member can't take the name of a generated member, or differ from another only
in case (
Openandopen), sinceTryParse(name, ignoreCase: true)couldn't tell them apart (CMTK1021). - A
ToString()you write is kept, and the name is still what JSON, parsing and the column use. - An overload of a generated method with another signature, such as
Parse(int rank)or a genericParse<TFormat>(string name), is kept too. Any other generated member written by hand fails the build (CMTK1011), in the set or in a class it derives from. Aprivateone in that class is fine, since the set can't see it. - A base class's
ToString(). Asealedone is kept, since C# keeps it in every derived class. One that isn't sealed fails the build (CMTK1011), because the generatedToString()would replace it. DeclareToString()in the set, or seal the base's. - An instance beside the members has no name. If the set's own code creates one, reading its name throws rather than writing a null.
- A JSON
nullreads asnull, as for any class, unless the serializer'sRespectNullableAnnotationsrejects it.
JSON
JsonSerializer.Serialize(new Order(OrderId.New(), Quantity.From(3)));
// {"Id":"0199a3f4-1c00-7000-8000-000000000001","Quantity":3}
JsonSerializer.Deserialize<Email>("\"not an address\""); // JsonException naming Email and NoAt, not the text
JsonSerializer.Deserialize<Dictionary<OrderId, int>>(json); // value objects work as dictionary keys
The JSON is the underlying value's, so an OrderId is a string and a Quantity a number.
The bytes are the serializer's own for the underlying type under the same options, both as a value
and as a dictionary key. So everything you set for the underlying type applies: a converter your
options register for it, number handling, an enum converter, and DictionaryKeyPolicy. Replacing a
Guid property with an OrderId changes no JSON. A test compares the two for every family of
underlying types, under several sets of options.
Numbers and dates are read as strictly as the serializer reads the underlying type. Input it can't
read throws a JsonException naming the value object and the underlying type ("Quantity could not
read the JSON value as Int32."), with no inner exception that could carry the text. ASP.NET Core
answers it with 400.
NodaTime types use NodaTime's converters when NodaTime.Serialization.SystemTextJson is referenced
and the options have none of their own. For JSON your application stored itself, see
StoredJsonConverterFactory in the base package.
Good to know
- A
DateTimeis written as UTC. This is the converter's one addition. ALocalvalue is converted, and anUnspecifiedone is taken as UTC with its digits kept. [JsonNumberHandling]on the containing type doesn't reach a value object. The attribute reaches the number properties the serializer writes itself, and a value object's converter never sees it. Under[JsonNumberHandling(WriteAsString | AllowReadingFromString)],record Dto(int Count)writes{"Count":"5"}and reads"5". Butrecord Dto(Quantity Count)writes{"Count":5}and rejects"5"with aJsonException. On the property itself, the serializer rejects the attribute for any type but a number (InvalidOperationException). Set the number handling on the options, or on a source-generated context's[JsonSourceGenerationOptions]. Both reach the value object.
A JSON null is rejected for a struct value object. A sealed partial record reads it as null,
as any class does, since the serializer calls no converter for it. RespectNullableAnnotations = true
on the options makes it reject null for a property that isn't declared nullable.
Preserved references (ReferenceHandler.Preserve) throw a NotSupportedException where the
serializer could write $id or $ref inside the underlying value. That's a class it walks as an
object, an object the serializer writes itself, or a struct, nullable or not, holding one in a
property that isn't ignored. The serializer numbers references per call, and the converter reaches
the underlying value through a call of its own, so its numbers wouldn't match the document's.
Register a JsonConverter for the underlying type, which writes no $id for it or for the value
object, or serialize without preserving references. These are unaffected: a value the serializer writes with a value converter (a number, a
string, a Guid, a Uri), anything a converter of your own writes, on the options or on one
property, a struct of such values, and ReferenceHandler.IgnoreCycles.
A missing property isn't rejected either. The serializer calls no converter for a property the
document lacks, and leaves it default. Mark the property required, or set
RespectRequiredConstructorParameters = true for a record's constructor parameters.
With a source-generated JsonSerializerContext (and so under Native AOT), list the value
objects, not the types they wrap. The context sees a value object's converter and never what it
wraps. So the converter builds that contract itself, as the serializer would: a converter on your
options first, then the underlying type's [JsonConverter], then the serializer's built-in
converter.
An enum is the exception. A context's UseStringEnumConverter doesn't reach an enum the context
doesn't list. So a value object over an enum is written as a number, unless you list the enum
([JsonSerializable(typeof(DayOfWeek))]) or name its converter
([JsonSourceGenerationOptions(Converters = [typeof(JsonStringEnumConverter<DayOfWeek>)])]).
A union or a closed class needs listing too. Neither has a converter to build the contract from, so list
it beside its value object ([JsonSerializable(typeof(Pet))]). Without it, the serializer throws
NotSupportedException naming the type to list.
Everything generated is trim- and AOT-safe, and the consumer smoke test publishes it with Native AOT.
Parsing and formatting
Quantity.Parse("3", null); // Quantity 3
Quantity.TryParse("x", null, out _); // false
Email.Parse("nobody", null); // FormatException naming Email and NoAt
var de = CultureInfo.GetCultureInfo("de-DE");
var text = Amount.From(1.5m).ToString(); // "1.5", whatever the current culture
var german = Amount.From(1.5m).ToString("N2", de); // "1,50"
var shown = $"{Amount.From(1.5m)}"; // "1.5"
Text is the same on every machine. A null IFormatProvider means the invariant culture in every
generated Parse, TryParse, ToString and TryFormat, so the text doesn't depend on the culture
the process runs in. ToString() is the underlying type's own default text under the invariant
culture, and the type converter and $"{x}" write the same.
That text reads back as the same value wherever the underlying type's own does: numbers (float,
double and Half included), BigInteger, Guid, DateOnly, TimeSpan, Version, Uri, enums
and strings.
Good to know
TimeOnly,DateTimeandDateTimeOffsetlose detail as text. Their default text drops what the invariant culture's short patterns drop.TimeOnly(3, 4, 5, 123)prints03:04, aDateTimeloses its fraction of a second and itsKind, and aDateTimeOffsetits fraction. Format those with"O"(x.ToString("O", null)), which aTimeOnlyand aDateTimeOffsetread back exactly. Or keep them in their JSON form, which aDateTimereads back as the UTC instant it wrote.- A provider you pass is used as given where the underlying type's parsing and formatting take
one. A
Uri, a NodaTime type, and a type parsed through a constructor or a provider-lessParseignore it. - A default instance formats as
""over a reference type, as it always did over a string. CMTK0001 keeps such an instance out of your own code, but EF Core, MVC and serializers can make one. "X"writes a hex float on .NET 11. There,double,floatandHalfformat"X"and"x"as a hexadecimal float: 1.5 is0X1.8P+0, or0X1,8P+0in a culture with a decimal comma. A value object over one writes the same. On .NET 10 the format throwsFormatException, for the value object as for the underlying type.Parsedoesn't read a hex float. The underlying type's default parsing rejects0X1.8P+0on .NET 10 and .NET 11, so the value object'sParserejects it too, without quoting it. To read one, call the underlying type'sParsewithNumberStyles.HexFloat(.NET 11), thenFrom.- No
TryParsePartial. .NET 11 addsTryParsePartialto the number types. It reads a number from the start of a text and tells you how much it read. A value object doesn't offer it, because its members are the same on .NET 10 and .NET 11. Call it on the underlying type and pass the number toFromorTryFrom.
When text is rejected
Text the underlying type can't read throws a FormatException naming the value object and the
underlying type ("Quantity could not read the input as Int32."), an overflow included. It has no inner
exception, because the underlying type's own message quotes the input. A rejection by Create names
the error instead.
The one place the input still appears is System.Text.Json's own: a rejected dictionary key ends the
JsonException's Path.
TryParse answers false for both. It lets anything else through, as Parse does: an exception
Create throws is a bug you should see, not text to reject.
A null string is false as well, whatever the underlying type's parser makes of one. Text the
underlying type's own parser answers with null is text it can't read: Parse throws that
FormatException and TryParse answers false.
Comparison
CompareTo and the operators follow the underlying type's ordering, ordinal for a string.
To order differently, declare CompareTo(TSelf) yourself. It's kept, and the object overload, the
operators and the interfaces are built from it. Any other hand-written comparison member fails the
build (CMTK1008), an explicit implementation of IComparable<TSelf>, IComparable or
IComparisonOperators included, in an interface the value object implements too. So in memory,
every comparison agrees with your CompareTo.
A database can't run your CompareTo, because it orders the column by the underlying value. So the
type carries [HandWrittenOrdering], and an EF Core query that compares or orders it, or takes its
Min or Max, is rejected, naming the value object, rather than answered in the column's order
(CodoMetis.TypeKit.EntityFrameworkCore).
Compare or order by .Value where the underlying value's order is what you mean.
Build errors
A declaration that can't be generated fails the build, so no type is left half-generated. Every error ends with a link to this table. CMTK1023 is the one warning:
| Id | Meaning |
|---|---|
| CMTK1000 | Not declared partial. |
| CMTK1001 | Not a record. |
| CMTK1002 | A struct not declared readonly. |
| CMTK1003 | More than one marker, such as IValue<int>, IValue<string>. |
| CMTK1004 | An IValidatedValue<TSelf, ...> whose TSelf is another type. |
| CMTK1005 | Generic or nested in a generic type (nesting in a non-generic type is fine), file-local or nested in a file-local type, named Value or as another member the generators add (From, TryFrom, FromKnownGood, Revalidate, Parse, TryParse, TryFormat, MinValue, MaxValue, CompareTo), derived from another value object, or wrapping object, System.Enum, an array, a pointer, a nullable type, a generic type (a tuple included) or a value object (itself included). Wrap what the other value object wraps instead. A C# 15 union with a value-object marker fails too: it has a Value of its own and can hold no field, so wrap the union in a value object instead. |
| CMTK1006 | A record class not declared sealed. |
| CMTK1007 | The {TSelf}Extensions companion's name is taken by a declared type or by another value object's companion. |
| CMTK1008 | A hand-written comparison operator, object CompareTo or explicit implementation of a comparison interface beside the generated ones, on the value object, a base record or an interface it implements. |
| CMTK1009 | A hand-written instance constructor, including a positional record's parameter list such as OrderId(Guid Value). The constructor and Value are generated. A static constructor is fine. |
| CMTK1010 | Declared in more than one partial part. Metalama writes the generated ToString() into every part, which doesn't compile. A part a source generator adds, such as a [GeneratedRegex] method's, doesn't count. |
| CMTK1011 | A hand-written member or attribute the generators add (see "Write your own members", and for a closed set every generated member but ToString(), by signature, IParsable<TSelf>, [JsonConverter] and [TypeConverter]), an explicit implementation of an interface they implement, on the value object, a base record or an interface it implements, a hand-written equality (an operator == or != between two of the type included, which C# also reports as CS0111), a PrintMembers without ToString(), or Create implemented explicitly. |
| CMTK1012 | Instance state besides the underlying value: a field, an auto-property, a required member or a field-like event, declared or inherited. Compute it from Value, make it static, or wrap a type that holds all of it. |
| CMTK1013 | A closed set not declared partial. |
| CMTK1014 | A closed set not declared sealed. A set with subtypes isn't closed. A C# 15 closed class is abstract, so it can't be a closed set either: declare the set sealed partial class. |
| CMTK1015 | A closed set with no member. A member is a public static readonly field of the set's own type. |
| CMTK1016 | A closed set with a constructor that isn't private, so an instance beside its members could be made. |
| CMTK1017 | A closed set with a static member of its own type that isn't a public readonly field: a property, a field that isn't readonly, or a field that isn't public. Each of those is an instance that is no member. |
| CMTK1018 | A closed set that is generic or nested in a generic type. |
| CMTK1019 | A closed set's member not initialized with new where it's declared, and with nothing else. = Open would give one instance two names. A member set later, by a call, or by an expression that only starts with new, may be another member or null. |
| CMTK1020 | A closed set declared as a record. with copies a member into an instance that is none, and a record compares by value where members are singletons. |
| CMTK1021 | A closed set's member named as a member the generators add (Name, QualifiedName, All, Match, Parse, TryParse, ToString, the JSON or type converter), a set itself named as one of them (a member can't have the name of its type), or a member whose name differs from another member's only in case. Those collide in TryParse(name, ignoreCase: true), and in Match's parameters where the first letter is the difference. Also two members whose Match parameters would have one name, which lower-casing the first letter gives a member starting with the Kelvin sign (U+212A) and one starting with K. |
| CMTK1022 | An abstract type with a value-object marker. It would get no member, and a value held as it, of a type derived from it, would have no Value and be written as {}. Declare the marker on the sealed type. An abstract closed set is CMTK1014. A C# 15 closed class is abstract too, and the message says so: wrap it in a value object instead. |
| CMTK1023 | A warning, and the value object is generated. A base record declares Equals(TBase), GetHashCode() or IEquatable<TBase>.Equals, which the generated equality, the underlying value's, doesn't call. Remove them from the base, or derive from a record without them. |
The analyzers that come with the base package add CMTK0001 to CMTK0014. See CodoMetis.TypeKit.Analyzers.
LAMA0625 in a web project
From version 2.4.0 on, previews included, you don't get this error. Versions up to 2.3.x build on Metalama 2026.1, and its compiler is older than the .NET 11 SDK. A web project then fails to build (LAMA0625) in two cases:
- The .NET 11 SDK is the only SDK installed, as in a .NET 11 container image. The error names
Microsoft.CodeAnalysis.Razor.Compiler.dll. Anet10.0project fails too. - The project references
Microsoft.AspNetCore.OpenApi11. The error namesMicrosoft.AspNetCore.OpenApi.SourceGenerators.dll, whatever SDKs you have installed.
A web project that only references your domain project fails as well, because the generators come along with that reference.
Move to 2.4.0 if you can. To stay on 2.3.x, do one of these:
Keep the generators in the domain project. Put
PrivateAssets="all"on its reference to this package. This works when the web project declares no value object of its own.<PackageReference Include="CodoMetis.TypeKit.Generators" Version="2.3.1" PrivateAssets="all" />Reference Metalama 2027 yourself, in the project that references this package.
<PackageReference Include="Metalama.Framework" Version="2027.0.10-preview" />
Good to know
- A .NET 10 SDK beside the .NET 11 SDK fixes the first case only. Metalama then takes the Razor compiler from the .NET 10 SDK and warns (LAMA0617). No SDK has an older OpenAPI generator, so the second case still fails.
- With
Microsoft.AspNetCore.OpenApi11, move to 2.4.0. On 2.3.x either fix makes the project build, and the OpenAPI document then answers 500 (#286).
Reading the generated code
Set <MetalamaEmitCompilerTransformedFiles>true</MetalamaEmitCompilerTransformedFiles> in the project,
then open obj/Debug/net10.0/metalama/. Every generated member is there as ordinary C#.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- CodoMetis.TypeKit (>= 2.4.0-preview.3)
- Metalama.Framework (>= 2027.0.10-preview)
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 |
|---|---|---|
| 2.4.0-preview.3 | 0 | 12/3/2026 |
| 2.4.0-preview.2 | 57 | 11/30/2026 |
| 2.4.0-preview.1 | 60 | 11/30/2026 |
| 2.3.1 | 1,275 | 10/31/2026 |
| 2.3.0 | 406 | 10/29/2026 |
| 2.2.0 | 780 | 10/18/2026 |
| 2.1.0 | 1,291 | 10/15/2026 |
| 2.0.0 | 195 | 10/14/2026 |
| 1.5.1 | 145 | 10/11/2026 |
| 1.5.0 | 121 | 10/11/2026 |
| 1.0.0 | 160 | 9/28/2026 |
Added
- Generators: on .NET 11, a value object can wrap a C# 15 union or a closed class, and is written to JSON as what it wraps, byte for byte. A source-generated context, which Native AOT needs, lists the union or the closed class beside the value object (Unions and closed classes (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Generators/README.md#unions-and-closed-classes), #223 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/223)).
- Generators README: on .NET 11, "X" formats a value object over a double, float or Half as a hex float, as it does the underlying type, and Parse rejects one; a value object offers no TryParsePartial (Parsing and formatting (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Generators/README.md#parsing-and-formatting), #319 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/319)).
- Generators: on .NET 11, a value object can wrap Decimal32, Decimal64, Decimal128 or BFloat16, with the JSON, parsing, formatting, comparison and OpenAPI schema of the type it wraps. EF Core 11 maps none of the four, and rejects a value object over one as it rejects the type (Numbers (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/docs/value-objects.md#numbers), #212 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/212)).
- Testing: on .NET 11, ShouldBeCase<TCase>() checks which case a C# 15 union holds and hands it back, so result.ShouldBeError().ShouldBeCase<NotFound>() needs no switch. A failure names both cases and never their content. The package has a net11.0 asset for it, and its net10.0 asset is unchanged (CodoMetis.TypeKit.Testing (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Testing/README.md), #210 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/210)).
- Core and Analyzers: [UnionType] and [ClosedHierarchy] ask a type parameter for a C# 15 union or a closed class or record, as where can't, and CMTK0010 fails the build at any other type argument, a type that implements IUnion alone and a subtype of a closed class included; the compiler decides what each type is, so the check runs where a project compiles C# 15 (CMTK0010 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Analyzers/README.md#cmtk0010), #209 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/209)).
Changed
- Generators: the package now requires Metalama.Framework 2027.0.10-preview, the current Metalama 2027.0 preview, where 2.4.0-preview.2 required 2027.0.9-preview. A project that references Metalama.Framework itself moves with it (#381 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/381)).
- Generators: a union that declares a value-object marker fails with CMTK1005 naming the union, where it failed with CMTK1000 to CMTK1002 and a Metalama crash (LAMA0555, LAMA0041). A closed class with a marker (CMTK1022) or declared as a closed set (CMTK1014) is now named as closed (Build errors (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Generators/README.md#build-errors)).
- Analyzers: CMTK0008 now also warns at .NET 11's FullJoin whose key selectors unwrap two different value objects, orders.FullJoin(customers, o => o.Id.Value, c => c.Id.Value, …), as at the other joins. In a build that treats warnings as errors, that can report code that built before (CMTK0008 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Analyzers/README.md#cmtk0008), #273 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/273)).
- ASP.NET Core: the README says what ASP.NET Core 11 does with value objects: [Obsolete] on a value-object property is deprecated, except in an OpenAPI 3.0 document with components; a list or an array is named after its element; AddValidation() checks the body around a value object, and [StringLength] or [MaxLength] on a value-object property fails every request (Binding (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.AspNetCore/README.md#binding)).
- Core: the package has a net11.0 asset beside net10.0, with the same dependencies, for the one thing that differs there: reading the case a C# 15 union holds. A net11.0 project gets it with no change of its own.
- Analyzers: CMTK0005 now also warns where ImmutableArray<OrderId>.Builder.Count is set, builder.Count = count, which adds a default item for each one the count grows by; a constant zero, -- and -= aren't reported. In a build that treats warnings as errors, that can report code that built before (CMTK0005 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Analyzers/README.md#cmtk0005)).
- Analyzers: CMTK0005 now also warns at Array.Clear(ids) and ids.AsSpan().Clear() on an array or span of value objects, with a message of its own: clearing puts default back into every slot. A constant length of zero isn't reported. In a build that treats warnings as errors, that can report code that built before (CMTK0005 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Analyzers/README.md#cmtk0005)).
- Analyzers: CMTK0004 now also fails the build at Materialize called on a generic value object written by hand, Code<int>.Materialize(text), which skipped its rules unreported. It is an Error, so code that built before can fail: call Create there (CMTK0004 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Analyzers/README.md#cmtk0004), #353 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/353)).
- Analyzers: CMTK0006 now warns when a constructor sets a member only inside a lambda or a local function it doesn't call, Complete = () => Id = id, which runs later or never. In a build that treats warnings as errors, that can report code that built before (CMTK0006 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Analyzers/README.md#cmtk0006), #352 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/352)).
- Analyzers: CMTK0008 now also warns at a comparison whose arguments are named in another order, string.Equals(comparisonType: c, a: label.Value, b: title.Value). In a build that treats warnings as errors, that can report code that built before (CMTK0008 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Analyzers/README.md#cmtk0008), #355 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/355)).
- Analyzers: CMTK0014 now also warns at new FaultKind(), the same zero as new() and default. In a build that treats warnings as errors, that can report code that built before (CMTK0014 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Analyzers/README.md#cmtk0014), #354 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/354)).
Fixed
- ASP.NET Core: a merge-patch type that holds a patch of itself, Patch<NodePatch> inside NodePatch, crashed the process with a stack overflow while the OpenAPI document was made. It's described once below the patch, and {} where it repeats, as ASP.NET writes a recursive type it inlines (What the document says (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.AspNetCore/README.md#what-the-document-says), #365 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/365)).
- Analyzers: CMTK0003 no longer fails the build at await pending.TapAsync(log) on a Task<Option<T>> you hold, as it never did for a Task<Result<…>> (CMTK0003 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Analyzers/README.md#cmtk0003), #349 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/349)).
- Analyzers: CMTK0011's fix no longer changes what new Plugin() builds where a constructor's parameters are all optional. It adds public Plugin() : this(retries: 3) { }, and offers no fix beside a params array or two such constructors (CMTK0011 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Analyzers/README.md#cmtk0011), #350 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/350)).
- Generators: a protected internal nested value object gets its {TSelf}Extensions class, internal, so GetValue() and ValueOrNull() work on it. It had none (What is generated (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Generators/README.md#what-is-generated), #360 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/360)).
- Generators: a closed set builds with a member declared as an escaped keyword, @default, and names it default. The build failed with LAMA0041 (Handle every member (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/docs/closed-sets.md#handle-every-member), #361 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/361)).
- Generators: a closed-set member created with one new is no longer refused with CMTK1019 for a ) inside a raw, interpolated or UTF-8 string argument, new("""a)b""") (Rules for a closed set (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Generators/README.md#rules-for-a-closed-set), #362 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/362)).
- Generators: a value object that inherits Create from a base record in another project builds with an overload the generated call can't mean beside it, such as Create(int) over a string. It was refused with CMTK1011 (Write your own members (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Generators/README.md#write-your-own-members), #363 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/363)).
- EF Core: on EF Core 11 at compatibility level 170 (SQL Server 2025), o.Tags.Contains(tag) over a list of value objects answers the rows it answers in memory, for every type inside. EF writes JSON_CONTAINS there, which picked another path for a value object than for the type inside: over a value object wrapping a string, Contains(null) found no row. TypeKit now writes it as o.Tags.Where(t => t == tag).Any(), in queries and query filters. A list of a nullable struct value object, List<OrderId?>, is refused there, naming it (On SQL Server (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.EntityFrameworkCore/README.md#on-sql-server), #325 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/325)).
- Generators: a value object over a union with a string case has no Parse. It parsed every text as that case, so Parse("5") over union(int, string) gave the text "5", written as "5" where From(5) writes 5.
- Generators: From rejects a union that holds no case, its default, as it rejects a null. It was written to JSON as null, which the value object then refused to read.
- Base: on .NET 11, a value object writes and reads a number as its wrapped type does where a resolver sets number handling on the wrapped type's contract. The serializer's number converters apply the options' number handling themselves there, so a value object over a double wrote "0.25" where its contract said to write 0.25 (#334 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/334)).
- ASP.NET Core: on .NET 11, each case of a C# 15 union is described in the OpenAPI document, a value object as its underlying type and a closed set as the enum of its names. A case was {}, which accepts anything, unless another endpoint had made its component (What the document says (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.AspNetCore/README.md#what-the-document-says), #321 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/321)).
- JSON: under WhenWritingDefault, a record value object holding its wrapped type's default (Points.From(0)) was written where an int 0 is left out. Add ValueObjectJsonModifiers.WhenWritingDefault to your resolver and it's left out too (Leaving out a default (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/docs/json.md#leaving-out-a-default), #324 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/324)).
- Core, Testing: on .NET 11, a message that prints an error prints the case a C# 15 union holds, as it prints an enum error's member: Slug refused the input (SlugTooLong { Length = 13 }). from Parse, a JSON read and FromKnownGood, and is the error SlugTooLong { Length = 13 }. from ShouldBeSuccess() and ShouldBeError(expected). Each printed the union's type name, which says nothing about which rule failed. A union with a ToString() of its own prints that (A value object refused a value (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit/README.md#a-value-object-refused-a-value), #331 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/331)).
- Generators: a base record's explicit IEquatable<TBase> or arithmetic operator is found when the base is in another project. It was missed there: a HashSet of the base held two equal value objects, a public + was generated beside the base's, and CMTK1023 stayed silent (write your own members (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Generators/README.md#write-your-own-members), #356 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/356)).
- Generators: on .NET 11, a JSON read rejects a union that holds no case, as From does. A converter registered for the union could hand one back, and the value object then wrote null, which it refused to read (unions and closed classes (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Generators/README.md#unions-and-closed-classes), #357 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/357)).
- Base: text the underlying type's own parser answers with null is rejected: Parse and the type converter throw the FormatException, and TryParse answers false. They built a value object whose Value was null (when text is rejected (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Generators/README.md#when-text-is-rejected), #358 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/358)).
- Generators: TryParse answers false for a null string over every underlying type. Over one whose span parser reads empty input it answered true (when text is rejected (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Generators/README.md#when-text-is-rejected), #359 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/359)).
- ASP.NET Core: [FaultStatus<LookupFault>(nameof(LookupFault.Gone), 410)] on an enum alias, Gone = Missing, sets the status of the member it shares a value with. The host refused to start, saying the name was no member (a status per endpoint (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.AspNetCore/README.md#a-status-per-endpoint), #367 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/367)).
- ASP.NET Core: a nullable value object over a type described by anyOf or oneOf, such as a C# 15 union, admits null in the document where the host inlines every schema. The schema refused the null the endpoint wrote (what the document says (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.AspNetCore/README.md#what-the-document-says), #368 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/368)).
- ASP.NET Core: a property with a converter of its own on a value object or a closed set is no longer described as the underlying type, which the converter doesn't write. It's left as ASP.NET writes any custom converter (what the document says (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.AspNetCore/README.md#what-the-document-says), #369 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/369)).
- ASP.NET Core: on .NET 11 with schemas inlined, fault and rule are described on the problem only. A response type declared beside it with a problem's property names and more got them too (a Result as a response (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.AspNetCore/README.md#a-result-as-a-response), #370 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/370)).
- EF Core: the key of an owned collection's element (OwnsMany) over an integer value object is generated on add, as an int key there is. Two elements added without an id had one key, and the second couldn't be tracked (keys (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.EntityFrameworkCore/README.md#keys), #348 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/348)).
- EF Core: an ordering by a value object with its own CompareTo, boxed and reached through LeftJoin, RightJoin or .NET 11's FullJoin, is refused as through Join. The database ordered it by the stored value (queries (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.EntityFrameworkCore/README.md#queries), #366 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/366)).
- Base: the JSON refusal of an Option or a Result over a type nested in a generic type, Option<Scope<int>.Payload>, is the NotSupportedException again. Naming the type threw ArgumentOutOfRangeException. A refusal now names a nested type with its containing types, Scope<Int32>.Payload, and so does the message of a default Fault<A, B> (not wire types (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit/README.md#not-wire-types), #351 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/351)).
- Serilog: Destructure.WithTypeKit() no longer keeps a collectible assembly from unloading. It remembered every type it was asked about for the life of the process (#364 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/364)).
Full changelog: https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/main/CHANGELOG.md