IxSoftware.Generators.IdGenerator 1.3.0

dotnet add package IxSoftware.Generators.IdGenerator --version 1.3.0                
NuGet\Install-Package IxSoftware.Generators.IdGenerator -Version 1.3.0                
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="IxSoftware.Generators.IdGenerator" Version="1.3.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add IxSoftware.Generators.IdGenerator --version 1.3.0                
#r "nuget: IxSoftware.Generators.IdGenerator, 1.3.0"                
#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 IxSoftware.Generators.IdGenerator as a Cake Addin
#addin nuget:?package=IxSoftware.Generators.IdGenerator&version=1.3.0

// Install IxSoftware.Generators.IdGenerator as a Cake Tool
#tool nuget:?package=IxSoftware.Generators.IdGenerator&version=1.3.0                

Id Generator

This project adds a source generator to your project that creates identity types. It's used for types that identifies some resource. For example a user id or application id.

IEquatable

The source generator adds casting operators (explicit cast to, implicit cast from), equality checks, hash code, equals and ToString() (if it is not already provided).

It will get applied to a partial readonly struct that specifies IEquality on itself and has a single private readonly field with no constructors defined. The struct currently must be declared in a namespace, i.e. you cannot declare them as inner types.

Example:

public readonly partial struct UserId : IEquatable<UserId>
{
   private readonly Guid value;
}

This is all you have to write. Notice that this struct would not normally compile, so if it doesn't there's probably something wrong. If you need more than a single field you can use a tuple on the value field. Note that the field doesn't have to be named value.

You can add additional methods or static fields.

Note that the default ToString() method uses InvariantCulture. This means that if the underlying type is a DateTime or DateTimeOffset the result will be the wonky US date format.

IComparable

This library can also implement IComparable<T>. Simply add it to the list of interfaces and it should just work.

This will implement int CompareTo(T other) and the four value comparison operators.

Building

This project, or more specifically the test project, requires Visual Studio 16.8 to build and/or the 5.0 (or newer) version of the .NET Core SDK toolchain.

If this is in order the project should build either through Visual Studio or dotnet build. A NuGet package will get built.

License

This program is licensed under the MIT license. Please see license.txt for details.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

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
1.3.0 92 11/24/2024
1.2.3 414 1/13/2023
1.2.2 475 5/11/2021
1.2.1 520 12/19/2020
1.2.0 213 12/5/2020
1.1.1 258 11/10/2020
1.1.0 495 7/9/2020
1.0.0 544 7/8/2020

# 1.3.0
- Changed to incremental code generator.
- Updated nuget packages to fix security issue with System.Net.Http.
- Removed the workspace dependency.
- Fixed nullable context in Equals function.
- Added IEqualityOperators.
- Added IComparisonOperators interface if the type implements IComparable.
# 1.2.3
- Fixed `StackOverflowException` when using CompareTo.
# 1.2.2
- Fixed `NullRefereneException` when using `default` as a comparison base with reference types as base type.
# 1.2.1
- Added support for generic types.
# 1.2
- Add `?` to Equals parameter if nullable is enabled.
- Implements `IComparable<T>` automatically as well.
- Casting operator now calls `bool Validate()` if such a method is defined and throws an `System.ArgumentException` if it returns `false`.
- Using a DateTime or DateTimeOffset as a backing field will now return ISO 8601 date time in ToString by default.
# 1.1.1
- Fix for release of Visual Studio 2019 16.8 which changed the interface for source generators.
- Removed error messages for old versions of Visual Studio.
# 1.1
- `Equals` for when the type is a string now use ordinal compare rather than culture dependent comparison which is the default
- Small performance and memory improvements
- Added error message if trying to build with an old version of MSBuild or .NET Core toolchain
# 1.0
- First version
- Added IdGenerator