Meziantou.Framework.StronglyTypedId
2.3.9
Prefix Reserved
dotnet add package Meziantou.Framework.StronglyTypedId --version 2.3.9
NuGet\Install-Package Meziantou.Framework.StronglyTypedId -Version 2.3.9
<PackageReference Include="Meziantou.Framework.StronglyTypedId" Version="2.3.9" />
<PackageVersion Include="Meziantou.Framework.StronglyTypedId" Version="2.3.9" />
<PackageReference Include="Meziantou.Framework.StronglyTypedId" />
paket add Meziantou.Framework.StronglyTypedId --version 2.3.9
#r "nuget: Meziantou.Framework.StronglyTypedId, 2.3.9"
#:package Meziantou.Framework.StronglyTypedId@2.3.9
#addin nuget:?package=Meziantou.Framework.StronglyTypedId&version=2.3.9
#tool nuget:?package=Meziantou.Framework.StronglyTypedId&version=2.3.9
Meziantou.Framework.StronglyTypedId
The source generator generates constructors, properties, equality members, common interfaces, converters for multiple serializers
[StronglyTypedId<int>]
public partial struct ProjectId { }
or using typeof if you're not using a version of C# that supports generic attributes
[StronglyTypedId(typeof(int))]
public partial struct ProjectId { }
StronglyTypedId generates the following code:
[System.ComponentModel.TypeConverterAttribute(typeof(ProjectIdTypeConverter))]
[System.Text.Json.Serialization.JsonConverterAttribute(typeof(ProjectIdJsonConverter))]
[Newtonsoft.Json.JsonConverterAttribute(typeof(ProjectIdNewtonsoftJsonConverter))]
[MongoDB.Bson.Serialization.Attributes.BsonSerializerAttribute(typeof(ProjectIdMongoDBBsonSerializer))]
public partial struct ProjectId :
System.IEquatable<ProjectId>,
System.IParsable<ProjectId>, // .NET 7+
System.ISpanParsable<ProjectId>, // .NET 7+
IStronglyTypedId, // When Meziantou.Framework.StronglyTypedId.Interfaces is referenced
IStronglyTypedId<ProjectId>, // When Meziantou.Framework.StronglyTypedId.Interfaces is referenced
IComparable, IComparable<ProjectId> // When at least one of the interface is explicitly defined by the user
{
public int Value { get; }
public string ValueAsString { get; } // Value formatted using InvariantCulture
private ProjectId(int value);
public static ProjectId FromInt32(int value);
public static ProjectId Parse(string value);
public static ProjectId Parse(ReadOnlySpan<char> value);
public static bool TryParse(string value, out ProjectId result);
public static bool TryParse(ReadOnlySpan<char> value, out ProjectId result);
public override int GetHashCode();
public override bool Equals(object? other);
public bool Equals(ProjectId other);
public static bool operator ==(ProjectId a, ProjectId b);
public static bool operator !=(ProjectId a, ProjectId b);
public override string ToString();
private partial class CustomerIdTypeConverter : System.ComponentModel.TypeConverter
{
public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType);
public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value);
public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType);
public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType);
}
// Generated only when System.Text.Json is accessible
private partial class CustomerIdJsonConverter : System.Text.Json.Serialization.JsonConverter<ProjectId>
{
public override void Write(System.Text.Json.Utf8JsonWriter writer, ProjectId value, System.Text.Json.JsonSerializerOptions options);
public override ProjectId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options);
}
// Generated only when Newtonsoft.Json is accessible
private partial class CustomerIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter
{
public override bool CanRead { get; }
public override bool CanWrite { get; }
public override bool CanConvert(System.Type type);
public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer);
public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer);
}
// Generated only when MongoDB.Bson.Serialization.Serializers.SerializerBase is accessible
private partial class ProjectIdMongoDBBsonSerializer : MongoDB.Bson.Serialization.Serializers.SerializerBase<ProjectId>
{
public override ProjectId Deserialize(MongoDB.Bson.Serialization.BsonDeserializationContext context, MongoDB.Bson.Serialization.BsonDeserializationArgs args);
public override void Serialize(MongoDB.Bson.Serialization.BsonSerializationContext context, MongoDB.Bson.Serialization.BsonSerializationArgs args, ProjectId value);
}
}
If the Meziantou.Framework.StronglyTypedId.Interfaces NuGet package is present, the generator will implements IStronglyTypedId and IStronglyTypedId<T>.
Supported types
System.BooleanSystem.ByteSystem.DateTimeSystem.DateTimeOffsetSystem.DecimalSystem.DoubleSystem.GuidSystem.HalfSystem.Int16System.Int32System.Int64System.Int128System.Numerics.BigIntegerSystem.SByteSystem.SingleSystem.StringSystem.Uint16System.Uint32System.Uint64System.Uint128MongoDB.Bson.ObjectId
Configuration
You can configure the code generation using the [StronglyTypedIdAttribute] attribute:
[StronglyTypedId(idType: typeof(long),
generateSystemTextJsonConverter: true,
generateNewtonsoftJsonConverter: true,
generateSystemComponentModelTypeConverter: true,
generateMongoDBBsonSerialization: true,
addCodeGeneratedAttribute: true
)]
public partial struct ProjectId { }
You can generate IComparable, IComparable<T> and comparison operators by adding one interface:
[StronglyTypedId<int>]
public partial struct ProjectId : IComparable { }
// Generated by the source generator
public partial struct ProjectId : IComparable<ProjectId>
{
public int CompareTo(object? other);
public int CompareTo(ProjectId? other);
public static bool operator <(ProjectId? left, ProjectId? right);
public static bool operator <=(IdInt32Comparable? left, IdInt32Comparable? right);
public static bool operator >(IdInt32Comparable? left, IdInt32Comparable? right);
public static bool operator >=(IdInt32Comparable? left, IdInt32Comparable? right);
}
Additional resources
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. 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 is compatible. 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. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
-
net10.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (34)
Showing the top 5 NuGet packages that depend on Meziantou.Framework.StronglyTypedId:
| Package | Downloads |
|---|---|
|
Allegro.Extensions.Identifiers.Abstractions
Contains strongly typed identifiers abstractions. |
|
|
Aviendha.Core
Addons, customizations, and extensions for the ABP Framework |
|
|
Aviendha.BillingManagement.Domain.Shared
Addons, customizations, and extensions for the ABP Framework |
|
|
Aviendha.MailingListManagement.Domain.Shared
Addons, customizations, and extensions for the ABP Framework |
|
|
Aviendha.Ddd.Domain
Addons, customizations, and extensions for the ABP Framework |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on Meziantou.Framework.StronglyTypedId:
| Repository | Stars |
|---|---|
|
StefH/AnyOf
Use the AnyOf<TFirst, TSecond, ...> type to handle multiple defined types as input parameters or return values for methods.
|
| Version | Downloads | Last Updated |
|---|---|---|
| 2.3.9 | 1,056 | 10/27/2025 |
| 2.3.8 | 164 | 10/27/2025 |
| 2.3.7 | 1,400 | 10/19/2025 |
| 2.3.6 | 1,044 | 10/5/2025 |
| 2.3.5 | 1,169 | 9/21/2025 |
| 2.3.4 | 1,874 | 9/3/2025 |
| 2.3.3 | 14,927 | 3/15/2025 |
| 2.3.2 | 8,741 | 11/17/2024 |
| 2.3.1 | 3,727 | 10/10/2024 |
| 2.3.0 | 8,486 | 7/13/2024 |
| 2.2.0 | 6,914 | 3/21/2024 |
| 2.1.0 | 4,646 | 11/26/2023 |
| 2.0.0 | 607 | 11/19/2023 |
| 1.0.35 | 4,052 | 11/15/2023 |
| 1.0.34 | 4,492 | 9/5/2023 |
| 1.0.33 | 799 | 8/7/2023 |
| 1.0.32 | 6,837 | 3/26/2023 |
| 1.0.31 | 531 | 3/21/2023 |
| 1.0.30 | 369 | 3/20/2023 |
| 1.0.29 | 2,273 | 2/18/2023 |
| 1.0.28 | 8,313 | 1/3/2023 |
| 1.0.27 | 605 | 1/2/2023 |
| 1.0.26 | 426 | 1/2/2023 |
| 1.0.25 | 439 | 1/1/2023 |
| 1.0.24 | 476 | 12/27/2022 |
| 1.0.23 | 419 | 12/26/2022 |
| 1.0.22 | 2,897 | 8/10/2022 |
| 1.0.21 | 2,965 | 4/29/2022 |
| 1.0.20 | 652 | 4/23/2022 |
| 1.0.19 | 6,141 | 2/23/2022 |
| 1.0.18 | 595 | 2/12/2022 |
| 1.0.17 | 903 | 11/10/2021 |
| 1.0.16 | 610 | 11/8/2021 |
| 1.0.15 | 3,773 | 7/14/2021 |
| 1.0.14 | 555 | 6/30/2021 |
| 1.0.13 | 507 | 6/10/2021 |
| 1.0.12 | 1,008 | 5/14/2021 |
| 1.0.11 | 467 | 5/14/2021 |
| 1.0.10 | 556 | 4/25/2021 |
| 1.0.9 | 501 | 4/22/2021 |
| 1.0.8 | 2,096 | 2/17/2021 |
| 1.0.7 | 479 | 2/16/2021 |
| 1.0.6 | 526 | 2/16/2021 |
| 1.0.5 | 511 | 2/15/2021 |
| 1.0.4 | 564 | 2/8/2021 |
| 1.0.3 | 533 | 2/4/2021 |
| 1.0.2 | 484 | 2/4/2021 |
| 1.0.1 | 475 | 2/3/2021 |
| 1.0.0 | 579 | 2/1/2021 |