Version 0.x of this library used the helper library CodeGeneration.Roslyn by AArnott, for build-time source generation. In version 1.x this approach has been completely replaced in favour of source generators, as these are explicitly supported in .NET 5+. As part of this change, there were a number of additional features added and breaking changes made.
Breaking Changes
StronglyTypedIds namespace is required. In version 0.x of the library, the [StronglyTypedId] attribute was in the global namespace. In version 1.x, the attribute is in the StronglyTypedIds namespace, so you must add namespace StronglyTypedIds;.
The properties exposed by StronglyTypedIds have changed: there is no longer a generateJsonConverter property. Instead, this is infered based on the StronglyTypedIdConverters flags provided.
The String backing typed ID will throw if you call the constructor with a null value
New Features
The attributes can now auto-generate additional converter types such as EF Core ValueConverter and Dapper TypeHandler, as described in my blog posts. These are optional flags on the converters property.
Made interface implementations (IEquatable<T> and IComparable<T> currently) optional. This is to potentially support additional interfaces in future versions.
Added a NullableString backing type. Due to the behaviour of structs in c#, the String backing type ID may still be null, but you can't explicitly call the constructor with a null value. In contrast, you can do this with the NullableString backing type.
Added a [StronglyTypedIdDefaults] attribute to set default values for all [StronglyTypedId] attributes in your project. This is useful if you want to customise all the attributes, for example, if you want to generate additional converters by default. You can still override all the properties of a [StronglyTypedId] instance.
Bug Fixes
Some converters had incorrect implementations, such as in (#26). These have been addressed in version 1.x.
Better null handling has been added for the String backing type, handling issues such as #32.
The code is marked as auto generated, to avoid errors such as #CS1591 as described in #27
Initial conversion to source generators.
Changes in version 1.x
Version 0.x of this library used the helper library CodeGeneration.Roslyn by AArnott, for build-time source generation. In version 1.x this approach has been completely replaced in favour of source generators, as these are explicitly supported in .NET 5+. As part of this change, there were a number of additional features added and breaking changes made.
Breaking Changes
StronglyTypedIds
namespace is required. In version 0.x of the library, the[StronglyTypedId]
attribute was in the global namespace. In version 1.x, the attribute is in theStronglyTypedIds
namespace, so you must addnamespace StronglyTypedIds;
.StronglyTypedIds
have changed: there is no longer agenerateJsonConverter
property. Instead, this is infered based on theStronglyTypedIdConverters
flags provided.String
backing typed ID will throw if you call the constructor with anull
valueNew Features
ValueConverter
and DapperTypeHandler
, as described in my blog posts. These are optional flags on theconverters
property.IEquatable<T>
andIComparable<T>
currently) optional. This is to potentially support additional interfaces in future versions.NullableString
backing type. Due to the behaviour ofstruct
s in c#, theString
backing type ID may still be null, but you can't explicitly call the constructor with a null value. In contrast, you can do this with theNullableString
backing type.[StronglyTypedIdDefaults]
attribute to set default values for all[StronglyTypedId]
attributes in your project. This is useful if you want to customise all the attributes, for example, if you want to generate additional converters by default. You can still override all the properties of a[StronglyTypedId]
instance.Bug Fixes
String
backing type, handling issues such as #32.