Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source generators implementation v1.x.0 #37

Merged
merged 65 commits into from
Nov 25, 2021
Merged

Conversation

andrewlock
Copy link
Owner

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 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

andrewlock and others added 30 commits July 6, 2021 23:26
It fails to restore until you build the first project, and it's fraught with caching issues, e.g. NuGet/Home#6579
So that it works in lower versions of the SDK
e.g. see dotnet/roslyn#54710 (comment)
- Expand the Converters type
- Add a "Defaults" assembly attribute for easier configuration of the defaults
- Allow not using _any_ converters
- Rename JsonConverters to Converters (as may want to add others, e.g. EF Core converters etc)
Refactor the source gen helper as we are getting more and more resources
- Fix issues in numeric IDs
- Support convertTo
Updated to net462 to support long file paths
@andrewlock andrewlock merged commit b44ab92 into master Nov 25, 2021
@andrewlock andrewlock deleted the source-generator branch November 25, 2021 22:39
vdurante pushed a commit to vdurante/StronglyTypedId that referenced this pull request Feb 29, 2024
Source generators implementation v1.0.0-beta
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant