diff --git a/src/StronglyTypedIds.Attributes/StronglyTypedIdImplementations.cs b/src/StronglyTypedIds.Attributes/StronglyTypedIdImplementations.cs
index d0900fc4f..e4d65d858 100644
--- a/src/StronglyTypedIds.Attributes/StronglyTypedIdImplementations.cs
+++ b/src/StronglyTypedIds.Attributes/StronglyTypedIdImplementations.cs
@@ -33,5 +33,17 @@ public enum StronglyTypedIdImplementations
/// Implement the interface
///
IComparable = 4,
+
+ // ReSharper disable once InconsistentNaming
+ ///
+ /// Implement an explicit cast
+ ///
+ ExplicitCast = 8,
+
+ // ReSharper disable once InconsistentNaming
+ ///
+ /// Implement an explicit cast
+ ///
+ ImplicitCast = 16,
}
}
\ No newline at end of file
diff --git a/src/StronglyTypedIds/EmbeddedSources.cs b/src/StronglyTypedIds/EmbeddedSources.cs
index e1f229779..8580b10ec 100644
--- a/src/StronglyTypedIds/EmbeddedSources.cs
+++ b/src/StronglyTypedIds/EmbeddedSources.cs
@@ -25,6 +25,8 @@ internal static class EmbeddedSources
LoadEmbeddedResource("StronglyTypedIds.Templates.Guid.Guid_EfCoreValueConverter.cs"),
LoadEmbeddedResource("StronglyTypedIds.Templates.Guid.Guid_DapperTypeHandler.cs"),
LoadEmbeddedResource("StronglyTypedIds.Templates.Guid.Guid_IComparable.cs"),
+ LoadEmbeddedResource("StronglyTypedIds.Templates.Guid.Guid_ImplicitCast.cs"),
+ LoadEmbeddedResource("StronglyTypedIds.Templates.Guid.Guid_ExplicitCast.cs"),
false
);
@@ -37,6 +39,8 @@ internal static class EmbeddedSources
LoadEmbeddedResource("StronglyTypedIds.Templates.Int.Int_EfCoreValueConverter.cs"),
LoadEmbeddedResource("StronglyTypedIds.Templates.Int.Int_DapperTypeHandler.cs"),
LoadEmbeddedResource("StronglyTypedIds.Templates.Int.Int_IComparable.cs"),
+ LoadEmbeddedResource("StronglyTypedIds.Templates.Int.Int_ImplicitCast.cs"),
+ LoadEmbeddedResource("StronglyTypedIds.Templates.Int.Int_ExplicitCast.cs"),
false
);
@@ -49,6 +53,8 @@ internal static class EmbeddedSources
LoadEmbeddedResource("StronglyTypedIds.Templates.Long.Long_EfCoreValueConverter.cs"),
LoadEmbeddedResource("StronglyTypedIds.Templates.Long.Long_DapperTypeHandler.cs"),
LoadEmbeddedResource("StronglyTypedIds.Templates.Long.Long_IComparable.cs"),
+ LoadEmbeddedResource("StronglyTypedIds.Templates.Long.Long_ImplicitCast.cs"),
+ LoadEmbeddedResource("StronglyTypedIds.Templates.Long.Long_ExplicitCast.cs"),
false
);
@@ -61,6 +67,8 @@ internal static class EmbeddedSources
LoadEmbeddedResource("StronglyTypedIds.Templates.String.String_EfCoreValueConverter.cs"),
LoadEmbeddedResource("StronglyTypedIds.Templates.String.String_DapperTypeHandler.cs"),
LoadEmbeddedResource("StronglyTypedIds.Templates.String.String_IComparable.cs"),
+ LoadEmbeddedResource("StronglyTypedIds.Templates.String.String_ImplicitCast.cs"),
+ LoadEmbeddedResource("StronglyTypedIds.Templates.String.String_ExplicitCast.cs"),
false
);
@@ -73,6 +81,8 @@ internal static class EmbeddedSources
LoadEmbeddedResource("StronglyTypedIds.Templates.NullableString.NullableString_EfCoreValueConverter.cs"),
LoadEmbeddedResource("StronglyTypedIds.Templates.NullableString.NullableString_DapperTypeHandler.cs"),
LoadEmbeddedResource("StronglyTypedIds.Templates.NullableString.NullableString_IComparable.cs"),
+ LoadEmbeddedResource("StronglyTypedIds.Templates.NullableString.NullableString_ImplicitCast.cs"),
+ LoadEmbeddedResource("StronglyTypedIds.Templates.NullableString.NullableString_ExplicitCast.cs"),
true
);
@@ -85,6 +95,8 @@ internal static class EmbeddedSources
LoadEmbeddedResource("StronglyTypedIds.Templates.NewId.NewId_EfCoreValueConverter.cs"),
LoadEmbeddedResource("StronglyTypedIds.Templates.NewId.NewId_DapperTypeHandler.cs"),
LoadEmbeddedResource("StronglyTypedIds.Templates.NewId.NewId_IComparable.cs"),
+ LoadEmbeddedResource("StronglyTypedIds.Templates.NewId.NewId_ImplicitCast.cs"),
+ LoadEmbeddedResource("StronglyTypedIds.Templates.NewId.NewId_ExplicitCast.cs"),
false
);
@@ -117,6 +129,8 @@ public readonly struct ResourceCollection
public string EfCoreValueConverter { get; }
public string DapperTypeHandler { get; }
public string Comparable { get; }
+ public string ImplicitCast { get; }
+ public string ExplicitCast { get; }
public ResourceCollection(
string header,
@@ -127,6 +141,8 @@ public ResourceCollection(
string efCoreValueConverter,
string dapperTypeHandler,
string comparable,
+ string implicitCast,
+ string explicitCast,
bool nullableEnable)
{
BaseId = baseId;
@@ -136,6 +152,8 @@ public ResourceCollection(
EfCoreValueConverter = efCoreValueConverter;
DapperTypeHandler = dapperTypeHandler;
Comparable = comparable;
+ ImplicitCast = implicitCast;
+ ExplicitCast = explicitCast;
NullableEnable = nullableEnable;
Header = header;
}
diff --git a/src/StronglyTypedIds/SourceGenerationHelper.cs b/src/StronglyTypedIds/SourceGenerationHelper.cs
index e33515310..0abbfccc7 100644
--- a/src/StronglyTypedIds/SourceGenerationHelper.cs
+++ b/src/StronglyTypedIds/SourceGenerationHelper.cs
@@ -72,7 +72,14 @@ static string CreateId(
var useIEquatable = implementations.IsSet(StronglyTypedIdImplementations.IEquatable);
var useIComparable = implementations.IsSet(StronglyTypedIdImplementations.IComparable);
+ var useImplicitCast = implementations.IsSet(StronglyTypedIdImplementations.ImplicitCast);
+ var useExplicitCast = implementations.IsSet(StronglyTypedIdImplementations.ExplicitCast);
+ if (useImplicitCast && useExplicitCast)
+ {
+ throw new ArgumentException("Cannot use implicit cast and explicit cast at the same time. Chose only one.", nameof(implementations));
+ }
+
var parentsCount = 0;
sb ??= new StringBuilder();
@@ -132,6 +139,16 @@ static string CreateId(
sb.AppendLine(resources.Comparable);
}
+ if (useImplicitCast)
+ {
+ sb.AppendLine(resources.ImplicitCast);
+ }
+
+ if (useExplicitCast)
+ {
+ sb.AppendLine(resources.ExplicitCast);
+ }
+
if (useEfCoreValueConverter)
{
sb.AppendLine(resources.EfCoreValueConverter);
diff --git a/src/StronglyTypedIds/Templates/Guid/Guid_ExplicitCast.cs b/src/StronglyTypedIds/Templates/Guid/Guid_ExplicitCast.cs
new file mode 100644
index 000000000..fd32da369
--- /dev/null
+++ b/src/StronglyTypedIds/Templates/Guid/Guid_ExplicitCast.cs
@@ -0,0 +1,2 @@
+ public static explicit operator System.Guid(TESTID id) => id.Value;
+ public static explicit operator TESTID(System.Guid value) => new(value);
\ No newline at end of file
diff --git a/src/StronglyTypedIds/Templates/Guid/Guid_ImplicitCast.cs b/src/StronglyTypedIds/Templates/Guid/Guid_ImplicitCast.cs
new file mode 100644
index 000000000..f2809f92e
--- /dev/null
+++ b/src/StronglyTypedIds/Templates/Guid/Guid_ImplicitCast.cs
@@ -0,0 +1,2 @@
+ public static implicit operator System.Guid(TESTID id) => id.Value;
+ public static implicit operator TESTID(System.Guid value) => new(value);
\ No newline at end of file
diff --git a/src/StronglyTypedIds/Templates/Int/Int_ExplicitCast.cs b/src/StronglyTypedIds/Templates/Int/Int_ExplicitCast.cs
new file mode 100644
index 000000000..e68aeb846
--- /dev/null
+++ b/src/StronglyTypedIds/Templates/Int/Int_ExplicitCast.cs
@@ -0,0 +1,2 @@
+ public static explicit operator int(TESTID id) => id.Value;
+ public static explicit operator TESTID(int value) => new(value);
\ No newline at end of file
diff --git a/src/StronglyTypedIds/Templates/Int/Int_ImplicitCast.cs b/src/StronglyTypedIds/Templates/Int/Int_ImplicitCast.cs
new file mode 100644
index 000000000..3def768fb
--- /dev/null
+++ b/src/StronglyTypedIds/Templates/Int/Int_ImplicitCast.cs
@@ -0,0 +1,2 @@
+ public static implicit operator int(TESTID id) => id.Value;
+ public static implicit operator TESTID(int value) => new(value);
\ No newline at end of file
diff --git a/src/StronglyTypedIds/Templates/Long/Long_ExplicitCast.cs b/src/StronglyTypedIds/Templates/Long/Long_ExplicitCast.cs
new file mode 100644
index 000000000..160156d24
--- /dev/null
+++ b/src/StronglyTypedIds/Templates/Long/Long_ExplicitCast.cs
@@ -0,0 +1,2 @@
+ public static explicit operator long(TESTID id) => id.Value;
+ public static explicit operator TESTID(long value) => new(value);
\ No newline at end of file
diff --git a/src/StronglyTypedIds/Templates/Long/Long_ImplicitCast.cs b/src/StronglyTypedIds/Templates/Long/Long_ImplicitCast.cs
new file mode 100644
index 000000000..8d07cdc75
--- /dev/null
+++ b/src/StronglyTypedIds/Templates/Long/Long_ImplicitCast.cs
@@ -0,0 +1,2 @@
+ public static implicit operator long(TESTID id) => id.Value;
+ public static implicit operator TESTID(long value) => new(value);
\ No newline at end of file
diff --git a/src/StronglyTypedIds/Templates/NewId/NewId_ExplicitCast.cs b/src/StronglyTypedIds/Templates/NewId/NewId_ExplicitCast.cs
new file mode 100644
index 000000000..d31e6d93b
--- /dev/null
+++ b/src/StronglyTypedIds/Templates/NewId/NewId_ExplicitCast.cs
@@ -0,0 +1,2 @@
+ public static explicit operator MassTransit.NewId(TESTID id) => id.Value;
+ public static explicit operator TESTID(MassTransit.NewId value) => new(value);
\ No newline at end of file
diff --git a/src/StronglyTypedIds/Templates/NewId/NewId_ImplicitCast.cs b/src/StronglyTypedIds/Templates/NewId/NewId_ImplicitCast.cs
new file mode 100644
index 000000000..bf42c7a1a
--- /dev/null
+++ b/src/StronglyTypedIds/Templates/NewId/NewId_ImplicitCast.cs
@@ -0,0 +1,2 @@
+ public static implicit operator MassTransit.NewId(TESTID id) => id.Value;
+ public static implicit operator TESTID(MassTransit.NewId value) => new(value);
\ No newline at end of file
diff --git a/src/StronglyTypedIds/Templates/NullableString/NullableString_ExplicitCast.cs b/src/StronglyTypedIds/Templates/NullableString/NullableString_ExplicitCast.cs
new file mode 100644
index 000000000..72ee2f1b8
--- /dev/null
+++ b/src/StronglyTypedIds/Templates/NullableString/NullableString_ExplicitCast.cs
@@ -0,0 +1,2 @@
+ public static explicit operator string?(TESTID id) => id.Value;
+ public static explicit operator TESTID(string? value) => new(value);
\ No newline at end of file
diff --git a/src/StronglyTypedIds/Templates/NullableString/NullableString_ImplicitCast.cs b/src/StronglyTypedIds/Templates/NullableString/NullableString_ImplicitCast.cs
new file mode 100644
index 000000000..c5b1d4b94
--- /dev/null
+++ b/src/StronglyTypedIds/Templates/NullableString/NullableString_ImplicitCast.cs
@@ -0,0 +1,2 @@
+ public static implicit operator string?(TESTID id) => id.Value;
+ public static implicit operator TESTID(string? value) => new(value);
\ No newline at end of file
diff --git a/src/StronglyTypedIds/Templates/String/String_ExplicitCast.cs b/src/StronglyTypedIds/Templates/String/String_ExplicitCast.cs
new file mode 100644
index 000000000..5a37ae25e
--- /dev/null
+++ b/src/StronglyTypedIds/Templates/String/String_ExplicitCast.cs
@@ -0,0 +1,2 @@
+ public static explicit operator string(TESTID id) => id.Value;
+ public static explicit operator TESTID(string value) => new(value);
\ No newline at end of file
diff --git a/src/StronglyTypedIds/Templates/String/String_ImplicitCast.cs b/src/StronglyTypedIds/Templates/String/String_ImplicitCast.cs
new file mode 100644
index 000000000..e1f1bcc40
--- /dev/null
+++ b/src/StronglyTypedIds/Templates/String/String_ImplicitCast.cs
@@ -0,0 +1,2 @@
+ public static implicit operator string(TESTID id) => id.Value;
+ public static implicit operator TESTID(string value) => new(value);
\ No newline at end of file
diff --git a/test/StronglyTypedIds.IntegrationTests/GuidIdTests.cs b/test/StronglyTypedIds.IntegrationTests/GuidIdTests.cs
index 2905f70e6..a594aef52 100644
--- a/test/StronglyTypedIds.IntegrationTests/GuidIdTests.cs
+++ b/test/StronglyTypedIds.IntegrationTests/GuidIdTests.cs
@@ -272,6 +272,23 @@ public void ImplementsInterfaces()
#pragma warning restore 184
}
+ [Fact]
+ public void CanExplicitCast()
+ {
+ Assert.IsAssignableFrom((ExplicitCastGuidId)Guid.NewGuid());
+ Assert.IsAssignableFrom((Guid)ExplicitCastGuidId.New());
+ }
+
+ [Fact]
+ public void CanImplicitCast()
+ {
+ ImplicitCastGuidId castedId = Guid.NewGuid();
+ Assert.IsType(castedId);
+
+ Guid castedGuid = ImplicitCastGuidId.New();
+ Assert.IsType(castedGuid);
+ }
+
#if NET6_0_OR_GREATER
[Fact]
public void WhenConventionBasedEfCoreValueConverterUsesValueConverter()
diff --git a/test/StronglyTypedIds.IntegrationTests/Types/GuidId.cs b/test/StronglyTypedIds.IntegrationTests/Types/GuidId.cs
index 9ad651d72..31e61a356 100644
--- a/test/StronglyTypedIds.IntegrationTests/Types/GuidId.cs
+++ b/test/StronglyTypedIds.IntegrationTests/Types/GuidId.cs
@@ -37,4 +37,10 @@ public partial struct EquatableGuidId { }
[StronglyTypedId(implementations: StronglyTypedIdImplementations.IComparable)]
public partial struct ComparableGuidId { }
+
+ [StronglyTypedId(implementations: StronglyTypedIdImplementations.ExplicitCast)]
+ public partial struct ExplicitCastGuidId { }
+
+ [StronglyTypedId(implementations: StronglyTypedIdImplementations.ImplicitCast)]
+ public partial struct ImplicitCastGuidId { }
}
\ No newline at end of file
diff --git a/test/StronglyTypedIds.Tests/EnumHelper.cs b/test/StronglyTypedIds.Tests/EnumHelper.cs
index c6eb61aa0..6a26fd0df 100644
--- a/test/StronglyTypedIds.Tests/EnumHelper.cs
+++ b/test/StronglyTypedIds.Tests/EnumHelper.cs
@@ -38,8 +38,15 @@ public static IEnumerable AllConverters(bool includeDe
}
}
- public static IEnumerable AllImplementations(bool includeDefault = true, bool includeNone = true)
+ public static IEnumerable AllImplementations(
+ bool includeDefault = true,
+ bool includeNone = true,
+ StronglyTypedIdImplementations[] skip = null,
+ StronglyTypedIdImplementations[] only = null)
{
+ skip ??= Array.Empty();
+ only ??= Array.Empty();
+
// get highest value
var highestValue = Enum.GetValues(typeof(StronglyTypedIdImplementations))
.Cast()
@@ -50,7 +57,9 @@ public static IEnumerable AllImplementations(boo
{
var implementations = (StronglyTypedIdImplementations)i;
if (implementations.IsSet(StronglyTypedIdImplementations.Default) && !includeDefault
- || implementations == StronglyTypedIdImplementations.None && !includeNone)
+ || implementations == StronglyTypedIdImplementations.None && !includeNone
+ || skip.Any(s => implementations.IsSet(s))
+ || (only.Length > 0 && !only.Any(s => implementations.IsSet(s))))
{
continue;
}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.verified.txt
index 76835ffec..3fc8c6b25 100644
--- a/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.verified.txt
+++ b/test/StronglyTypedIds.Tests/Snapshots/EmbeddedResourceTests.EmittedResourceIsSameAsCompiledResource_resource=StronglyTypedIdImplementations.verified.txt
@@ -46,6 +46,18 @@ namespace StronglyTypedIds
/// Implement the interface
///
IComparable = 4,
+
+ // ReSharper disable once InconsistentNaming
+ ///
+ /// Implement an explicit cast
+ ///
+ ExplicitCast = 8,
+
+ // ReSharper disable once InconsistentNaming
+ ///
+ /// Implement an explicit cast
+ ///
+ ImplicitCast = 16,
}
}
#endif
\ No newline at end of file
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Guid_implementations=10.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Guid_implementations=10.verified.txt
new file mode 100644
index 000000000..14b98bb1a
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Guid_implementations=10.verified.txt
@@ -0,0 +1,41 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IEquatable
+ {
+ public System.Guid Value { get; }
+
+ public MyTestId(System.Guid value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(System.Guid.NewGuid());
+ public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static explicit operator System.Guid(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(System.Guid value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Guid_implementations=12.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Guid_implementations=12.verified.txt
new file mode 100644
index 000000000..8eea6eb50
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Guid_implementations=12.verified.txt
@@ -0,0 +1,42 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IComparable
+ {
+ public System.Guid Value { get; }
+
+ public MyTestId(System.Guid value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(System.Guid.NewGuid());
+ public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static explicit operator System.Guid(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(System.Guid value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Guid_implementations=14.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Guid_implementations=14.verified.txt
new file mode 100644
index 000000000..cfb7d0b40
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Guid_implementations=14.verified.txt
@@ -0,0 +1,42 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IComparable, System.IEquatable
+ {
+ public System.Guid Value { get; }
+
+ public MyTestId(System.Guid value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(System.Guid.NewGuid());
+ public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static explicit operator System.Guid(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(System.Guid value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Guid_implementations=16.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Guid_implementations=16.verified.txt
new file mode 100644
index 000000000..5b8624804
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Guid_implementations=16.verified.txt
@@ -0,0 +1,41 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId
+ {
+ public System.Guid Value { get; }
+
+ public MyTestId(System.Guid value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(System.Guid.NewGuid());
+ public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static implicit operator System.Guid(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(System.Guid value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Guid_implementations=18.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Guid_implementations=18.verified.txt
new file mode 100644
index 000000000..ea56c844e
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Guid_implementations=18.verified.txt
@@ -0,0 +1,41 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IEquatable
+ {
+ public System.Guid Value { get; }
+
+ public MyTestId(System.Guid value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(System.Guid.NewGuid());
+ public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static implicit operator System.Guid(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(System.Guid value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Guid_implementations=20.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Guid_implementations=20.verified.txt
new file mode 100644
index 000000000..c3484248d
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Guid_implementations=20.verified.txt
@@ -0,0 +1,42 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IComparable
+ {
+ public System.Guid Value { get; }
+
+ public MyTestId(System.Guid value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(System.Guid.NewGuid());
+ public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static implicit operator System.Guid(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(System.Guid value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Guid_implementations=22.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Guid_implementations=22.verified.txt
new file mode 100644
index 000000000..8295511c2
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Guid_implementations=22.verified.txt
@@ -0,0 +1,42 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IComparable, System.IEquatable
+ {
+ public System.Guid Value { get; }
+
+ public MyTestId(System.Guid value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(System.Guid.NewGuid());
+ public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static implicit operator System.Guid(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(System.Guid value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Guid_implementations=8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Guid_implementations=8.verified.txt
new file mode 100644
index 000000000..2923ba496
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Guid_implementations=8.verified.txt
@@ -0,0 +1,41 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId
+ {
+ public System.Guid Value { get; }
+
+ public MyTestId(System.Guid value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(System.Guid.NewGuid());
+ public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static explicit operator System.Guid(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(System.Guid value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Int_implementations=10.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Int_implementations=10.verified.txt
new file mode 100644
index 000000000..1a81dab32
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Int_implementations=10.verified.txt
@@ -0,0 +1,40 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IEquatable
+ {
+ public int Value { get; }
+
+ public MyTestId(int value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static explicit operator int(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(int value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Int_implementations=12.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Int_implementations=12.verified.txt
new file mode 100644
index 000000000..2a0dc73dd
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Int_implementations=12.verified.txt
@@ -0,0 +1,41 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IComparable
+ {
+ public int Value { get; }
+
+ public MyTestId(int value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static explicit operator int(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(int value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Int_implementations=14.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Int_implementations=14.verified.txt
new file mode 100644
index 000000000..4eec31de5
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Int_implementations=14.verified.txt
@@ -0,0 +1,41 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IComparable, System.IEquatable
+ {
+ public int Value { get; }
+
+ public MyTestId(int value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static explicit operator int(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(int value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Int_implementations=16.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Int_implementations=16.verified.txt
new file mode 100644
index 000000000..a9dde46f3
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Int_implementations=16.verified.txt
@@ -0,0 +1,40 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId
+ {
+ public int Value { get; }
+
+ public MyTestId(int value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static implicit operator int(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(int value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Int_implementations=18.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Int_implementations=18.verified.txt
new file mode 100644
index 000000000..c150123c9
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Int_implementations=18.verified.txt
@@ -0,0 +1,40 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IEquatable
+ {
+ public int Value { get; }
+
+ public MyTestId(int value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static implicit operator int(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(int value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Int_implementations=20.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Int_implementations=20.verified.txt
new file mode 100644
index 000000000..c74bada01
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Int_implementations=20.verified.txt
@@ -0,0 +1,41 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IComparable
+ {
+ public int Value { get; }
+
+ public MyTestId(int value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static implicit operator int(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(int value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Int_implementations=22.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Int_implementations=22.verified.txt
new file mode 100644
index 000000000..d8d2a3250
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Int_implementations=22.verified.txt
@@ -0,0 +1,41 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IComparable, System.IEquatable
+ {
+ public int Value { get; }
+
+ public MyTestId(int value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static implicit operator int(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(int value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Int_implementations=8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Int_implementations=8.verified.txt
new file mode 100644
index 000000000..72c7a01d2
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Int_implementations=8.verified.txt
@@ -0,0 +1,40 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId
+ {
+ public int Value { get; }
+
+ public MyTestId(int value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static explicit operator int(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(int value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Long_implementations=10.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Long_implementations=10.verified.txt
new file mode 100644
index 000000000..bb6b2634c
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Long_implementations=10.verified.txt
@@ -0,0 +1,40 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IEquatable
+ {
+ public long Value { get; }
+
+ public MyTestId(long value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static explicit operator long(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(long value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Long_implementations=12.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Long_implementations=12.verified.txt
new file mode 100644
index 000000000..984c91afe
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Long_implementations=12.verified.txt
@@ -0,0 +1,41 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IComparable
+ {
+ public long Value { get; }
+
+ public MyTestId(long value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static explicit operator long(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(long value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Long_implementations=14.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Long_implementations=14.verified.txt
new file mode 100644
index 000000000..338d72fd9
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Long_implementations=14.verified.txt
@@ -0,0 +1,41 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IComparable, System.IEquatable
+ {
+ public long Value { get; }
+
+ public MyTestId(long value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static explicit operator long(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(long value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Long_implementations=16.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Long_implementations=16.verified.txt
new file mode 100644
index 000000000..ed3a11493
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Long_implementations=16.verified.txt
@@ -0,0 +1,40 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId
+ {
+ public long Value { get; }
+
+ public MyTestId(long value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static implicit operator long(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(long value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Long_implementations=18.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Long_implementations=18.verified.txt
new file mode 100644
index 000000000..937a9b8ed
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Long_implementations=18.verified.txt
@@ -0,0 +1,40 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IEquatable
+ {
+ public long Value { get; }
+
+ public MyTestId(long value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static implicit operator long(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(long value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Long_implementations=20.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Long_implementations=20.verified.txt
new file mode 100644
index 000000000..eb51942d2
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Long_implementations=20.verified.txt
@@ -0,0 +1,41 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IComparable
+ {
+ public long Value { get; }
+
+ public MyTestId(long value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static implicit operator long(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(long value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Long_implementations=22.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Long_implementations=22.verified.txt
new file mode 100644
index 000000000..e9c1daeea
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Long_implementations=22.verified.txt
@@ -0,0 +1,41 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IComparable, System.IEquatable
+ {
+ public long Value { get; }
+
+ public MyTestId(long value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static implicit operator long(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(long value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Long_implementations=8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Long_implementations=8.verified.txt
new file mode 100644
index 000000000..7b2c65f35
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=Long_implementations=8.verified.txt
@@ -0,0 +1,40 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId
+ {
+ public long Value { get; }
+
+ public MyTestId(long value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static explicit operator long(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(long value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=MassTransitNewId_implementations=10.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=MassTransitNewId_implementations=10.verified.txt
new file mode 100644
index 000000000..6f824f15b
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=MassTransitNewId_implementations=10.verified.txt
@@ -0,0 +1,41 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IEquatable
+ {
+ public MassTransit.NewId Value { get; }
+
+ public MyTestId(MassTransit.NewId value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(MassTransit.NewId.Next());
+ public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static explicit operator MassTransit.NewId(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(MassTransit.NewId value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=MassTransitNewId_implementations=12.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=MassTransitNewId_implementations=12.verified.txt
new file mode 100644
index 000000000..d3915ba22
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=MassTransitNewId_implementations=12.verified.txt
@@ -0,0 +1,42 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IComparable
+ {
+ public MassTransit.NewId Value { get; }
+
+ public MyTestId(MassTransit.NewId value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(MassTransit.NewId.Next());
+ public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static explicit operator MassTransit.NewId(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(MassTransit.NewId value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=MassTransitNewId_implementations=14.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=MassTransitNewId_implementations=14.verified.txt
new file mode 100644
index 000000000..ece313cfd
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=MassTransitNewId_implementations=14.verified.txt
@@ -0,0 +1,42 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IComparable, System.IEquatable
+ {
+ public MassTransit.NewId Value { get; }
+
+ public MyTestId(MassTransit.NewId value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(MassTransit.NewId.Next());
+ public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static explicit operator MassTransit.NewId(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(MassTransit.NewId value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=MassTransitNewId_implementations=16.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=MassTransitNewId_implementations=16.verified.txt
new file mode 100644
index 000000000..e73283a0c
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=MassTransitNewId_implementations=16.verified.txt
@@ -0,0 +1,41 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId
+ {
+ public MassTransit.NewId Value { get; }
+
+ public MyTestId(MassTransit.NewId value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(MassTransit.NewId.Next());
+ public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static implicit operator MassTransit.NewId(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(MassTransit.NewId value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=MassTransitNewId_implementations=18.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=MassTransitNewId_implementations=18.verified.txt
new file mode 100644
index 000000000..cbbdb5ee7
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=MassTransitNewId_implementations=18.verified.txt
@@ -0,0 +1,41 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IEquatable
+ {
+ public MassTransit.NewId Value { get; }
+
+ public MyTestId(MassTransit.NewId value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(MassTransit.NewId.Next());
+ public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static implicit operator MassTransit.NewId(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(MassTransit.NewId value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=MassTransitNewId_implementations=20.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=MassTransitNewId_implementations=20.verified.txt
new file mode 100644
index 000000000..944873151
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=MassTransitNewId_implementations=20.verified.txt
@@ -0,0 +1,42 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IComparable
+ {
+ public MassTransit.NewId Value { get; }
+
+ public MyTestId(MassTransit.NewId value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(MassTransit.NewId.Next());
+ public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static implicit operator MassTransit.NewId(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(MassTransit.NewId value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=MassTransitNewId_implementations=22.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=MassTransitNewId_implementations=22.verified.txt
new file mode 100644
index 000000000..944780b29
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=MassTransitNewId_implementations=22.verified.txt
@@ -0,0 +1,42 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IComparable, System.IEquatable
+ {
+ public MassTransit.NewId Value { get; }
+
+ public MyTestId(MassTransit.NewId value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(MassTransit.NewId.Next());
+ public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static implicit operator MassTransit.NewId(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(MassTransit.NewId value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=MassTransitNewId_implementations=8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=MassTransitNewId_implementations=8.verified.txt
new file mode 100644
index 000000000..3703a347d
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=MassTransitNewId_implementations=8.verified.txt
@@ -0,0 +1,41 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId
+ {
+ public MassTransit.NewId Value { get; }
+
+ public MyTestId(MassTransit.NewId value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(MassTransit.NewId.Next());
+ public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static explicit operator MassTransit.NewId(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(MassTransit.NewId value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=NullableString_implementations=10.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=NullableString_implementations=10.verified.txt
new file mode 100644
index 000000000..9777f2e07
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=NullableString_implementations=10.verified.txt
@@ -0,0 +1,49 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+#nullable enable
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IEquatable
+ {
+ public string? Value { get; }
+
+ public MyTestId(string? value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(string.Empty);
+
+ public bool Equals(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => true,
+ (null, _) => false,
+ (_, null) => false,
+ (_, _) => Value.Equals(other.Value),
+ };
+ }
+ public override bool Equals(object? obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value?.GetHashCode() ?? 0;
+ public override string? ToString() => Value;
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static explicit operator string?(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(string? value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=NullableString_implementations=12.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=NullableString_implementations=12.verified.txt
new file mode 100644
index 000000000..ef9d1d395
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=NullableString_implementations=12.verified.txt
@@ -0,0 +1,59 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+#nullable enable
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IComparable
+ {
+ public string? Value { get; }
+
+ public MyTestId(string? value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(string.Empty);
+
+ public bool Equals(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => true,
+ (null, _) => false,
+ (_, null) => false,
+ (_, _) => Value.Equals(other.Value),
+ };
+ }
+ public override bool Equals(object? obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value?.GetHashCode() ?? 0;
+ public override string? ToString() => Value;
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => 0,
+ (null, _) => -1,
+ (_, null) => 1,
+ (_, _) => Value.CompareTo(other.Value),
+ };
+ }
+ public static explicit operator string?(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(string? value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=NullableString_implementations=14.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=NullableString_implementations=14.verified.txt
new file mode 100644
index 000000000..71286f454
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=NullableString_implementations=14.verified.txt
@@ -0,0 +1,59 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+#nullable enable
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IComparable, System.IEquatable
+ {
+ public string? Value { get; }
+
+ public MyTestId(string? value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(string.Empty);
+
+ public bool Equals(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => true,
+ (null, _) => false,
+ (_, null) => false,
+ (_, _) => Value.Equals(other.Value),
+ };
+ }
+ public override bool Equals(object? obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value?.GetHashCode() ?? 0;
+ public override string? ToString() => Value;
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => 0,
+ (null, _) => -1,
+ (_, null) => 1,
+ (_, _) => Value.CompareTo(other.Value),
+ };
+ }
+ public static explicit operator string?(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(string? value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=NullableString_implementations=16.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=NullableString_implementations=16.verified.txt
new file mode 100644
index 000000000..46bbcd70e
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=NullableString_implementations=16.verified.txt
@@ -0,0 +1,49 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+#nullable enable
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId
+ {
+ public string? Value { get; }
+
+ public MyTestId(string? value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(string.Empty);
+
+ public bool Equals(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => true,
+ (null, _) => false,
+ (_, null) => false,
+ (_, _) => Value.Equals(other.Value),
+ };
+ }
+ public override bool Equals(object? obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value?.GetHashCode() ?? 0;
+ public override string? ToString() => Value;
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static implicit operator string?(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(string? value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=NullableString_implementations=18.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=NullableString_implementations=18.verified.txt
new file mode 100644
index 000000000..73648d060
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=NullableString_implementations=18.verified.txt
@@ -0,0 +1,49 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+#nullable enable
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IEquatable
+ {
+ public string? Value { get; }
+
+ public MyTestId(string? value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(string.Empty);
+
+ public bool Equals(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => true,
+ (null, _) => false,
+ (_, null) => false,
+ (_, _) => Value.Equals(other.Value),
+ };
+ }
+ public override bool Equals(object? obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value?.GetHashCode() ?? 0;
+ public override string? ToString() => Value;
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static implicit operator string?(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(string? value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=NullableString_implementations=20.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=NullableString_implementations=20.verified.txt
new file mode 100644
index 000000000..63944f4aa
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=NullableString_implementations=20.verified.txt
@@ -0,0 +1,59 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+#nullable enable
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IComparable
+ {
+ public string? Value { get; }
+
+ public MyTestId(string? value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(string.Empty);
+
+ public bool Equals(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => true,
+ (null, _) => false,
+ (_, null) => false,
+ (_, _) => Value.Equals(other.Value),
+ };
+ }
+ public override bool Equals(object? obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value?.GetHashCode() ?? 0;
+ public override string? ToString() => Value;
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => 0,
+ (null, _) => -1,
+ (_, null) => 1,
+ (_, _) => Value.CompareTo(other.Value),
+ };
+ }
+ public static implicit operator string?(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(string? value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=NullableString_implementations=22.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=NullableString_implementations=22.verified.txt
new file mode 100644
index 000000000..d6d8fc8a6
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=NullableString_implementations=22.verified.txt
@@ -0,0 +1,59 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+#nullable enable
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IComparable, System.IEquatable
+ {
+ public string? Value { get; }
+
+ public MyTestId(string? value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(string.Empty);
+
+ public bool Equals(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => true,
+ (null, _) => false,
+ (_, null) => false,
+ (_, _) => Value.Equals(other.Value),
+ };
+ }
+ public override bool Equals(object? obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value?.GetHashCode() ?? 0;
+ public override string? ToString() => Value;
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => 0,
+ (null, _) => -1,
+ (_, null) => 1,
+ (_, _) => Value.CompareTo(other.Value),
+ };
+ }
+ public static implicit operator string?(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(string? value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=NullableString_implementations=8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=NullableString_implementations=8.verified.txt
new file mode 100644
index 000000000..bcbffc6a0
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=NullableString_implementations=8.verified.txt
@@ -0,0 +1,49 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+#nullable enable
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId
+ {
+ public string? Value { get; }
+
+ public MyTestId(string? value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(string.Empty);
+
+ public bool Equals(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => true,
+ (null, _) => false,
+ (_, null) => false,
+ (_, _) => Value.Equals(other.Value),
+ };
+ }
+ public override bool Equals(object? obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value?.GetHashCode() ?? 0;
+ public override string? ToString() => Value;
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static explicit operator string?(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(string? value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=String_implementations=10.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=String_implementations=10.verified.txt
new file mode 100644
index 000000000..1a970778f
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=String_implementations=10.verified.txt
@@ -0,0 +1,49 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IEquatable
+ {
+ public string Value { get; }
+
+ public MyTestId(string value)
+ {
+ Value = value ?? throw new System.ArgumentNullException(nameof(value));
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(string.Empty);
+
+ public bool Equals(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => true,
+ (null, _) => false,
+ (_, null) => false,
+ (_, _) => Value.Equals(other.Value),
+ };
+ }
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value;
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static explicit operator string(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(string value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=String_implementations=12.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=String_implementations=12.verified.txt
new file mode 100644
index 000000000..c4166dd60
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=String_implementations=12.verified.txt
@@ -0,0 +1,59 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IComparable
+ {
+ public string Value { get; }
+
+ public MyTestId(string value)
+ {
+ Value = value ?? throw new System.ArgumentNullException(nameof(value));
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(string.Empty);
+
+ public bool Equals(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => true,
+ (null, _) => false,
+ (_, null) => false,
+ (_, _) => Value.Equals(other.Value),
+ };
+ }
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value;
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => 0,
+ (null, _) => -1,
+ (_, null) => 1,
+ (_, _) => Value.CompareTo(other.Value),
+ };
+ }
+ public static explicit operator string(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(string value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=String_implementations=14.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=String_implementations=14.verified.txt
new file mode 100644
index 000000000..b7ea4ed46
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=String_implementations=14.verified.txt
@@ -0,0 +1,59 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IComparable, System.IEquatable
+ {
+ public string Value { get; }
+
+ public MyTestId(string value)
+ {
+ Value = value ?? throw new System.ArgumentNullException(nameof(value));
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(string.Empty);
+
+ public bool Equals(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => true,
+ (null, _) => false,
+ (_, null) => false,
+ (_, _) => Value.Equals(other.Value),
+ };
+ }
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value;
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => 0,
+ (null, _) => -1,
+ (_, null) => 1,
+ (_, _) => Value.CompareTo(other.Value),
+ };
+ }
+ public static explicit operator string(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(string value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=String_implementations=16.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=String_implementations=16.verified.txt
new file mode 100644
index 000000000..cbc3ef5c3
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=String_implementations=16.verified.txt
@@ -0,0 +1,49 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId
+ {
+ public string Value { get; }
+
+ public MyTestId(string value)
+ {
+ Value = value ?? throw new System.ArgumentNullException(nameof(value));
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(string.Empty);
+
+ public bool Equals(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => true,
+ (null, _) => false,
+ (_, null) => false,
+ (_, _) => Value.Equals(other.Value),
+ };
+ }
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value;
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static implicit operator string(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(string value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=String_implementations=18.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=String_implementations=18.verified.txt
new file mode 100644
index 000000000..930731914
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=String_implementations=18.verified.txt
@@ -0,0 +1,49 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IEquatable
+ {
+ public string Value { get; }
+
+ public MyTestId(string value)
+ {
+ Value = value ?? throw new System.ArgumentNullException(nameof(value));
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(string.Empty);
+
+ public bool Equals(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => true,
+ (null, _) => false,
+ (_, null) => false,
+ (_, _) => Value.Equals(other.Value),
+ };
+ }
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value;
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static implicit operator string(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(string value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=String_implementations=20.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=String_implementations=20.verified.txt
new file mode 100644
index 000000000..f35a93dd0
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=String_implementations=20.verified.txt
@@ -0,0 +1,59 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IComparable
+ {
+ public string Value { get; }
+
+ public MyTestId(string value)
+ {
+ Value = value ?? throw new System.ArgumentNullException(nameof(value));
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(string.Empty);
+
+ public bool Equals(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => true,
+ (null, _) => false,
+ (_, null) => false,
+ (_, _) => Value.Equals(other.Value),
+ };
+ }
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value;
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => 0,
+ (null, _) => -1,
+ (_, null) => 1,
+ (_, _) => Value.CompareTo(other.Value),
+ };
+ }
+ public static implicit operator string(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(string value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=String_implementations=22.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=String_implementations=22.verified.txt
new file mode 100644
index 000000000..4f2e755c2
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=String_implementations=22.verified.txt
@@ -0,0 +1,59 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId : System.IComparable, System.IEquatable
+ {
+ public string Value { get; }
+
+ public MyTestId(string value)
+ {
+ Value = value ?? throw new System.ArgumentNullException(nameof(value));
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(string.Empty);
+
+ public bool Equals(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => true,
+ (null, _) => false,
+ (_, null) => false,
+ (_, _) => Value.Equals(other.Value),
+ };
+ }
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value;
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => 0,
+ (null, _) => -1,
+ (_, null) => 1,
+ (_, _) => Value.CompareTo(other.Value),
+ };
+ }
+ public static implicit operator string(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(string value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=String_implementations=8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=String_implementations=8.verified.txt
new file mode 100644
index 000000000..cc2dc54fb
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=0_backingType=String_implementations=8.verified.txt
@@ -0,0 +1,49 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ readonly partial struct MyTestId
+ {
+ public string Value { get; }
+
+ public MyTestId(string value)
+ {
+ Value = value ?? throw new System.ArgumentNullException(nameof(value));
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(string.Empty);
+
+ public bool Equals(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => true,
+ (null, _) => false,
+ (_, null) => false,
+ (_, _) => Value.Equals(other.Value),
+ };
+ }
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value;
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static explicit operator string(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(string value) => new(value);
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Guid_implementations=10.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Guid_implementations=10.verified.txt
new file mode 100644
index 000000000..bb1a69eeb
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Guid_implementations=10.verified.txt
@@ -0,0 +1,97 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IEquatable
+ {
+ public System.Guid Value { get; }
+
+ public MyTestId(System.Guid value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(System.Guid.NewGuid());
+ public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static explicit operator System.Guid(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(System.Guid value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ return value switch
+ {
+ System.Guid guidValue => new MyTestId(guidValue),
+ string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result),
+ _ => base.ConvertFrom(context, culture, value),
+ };
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(System.Guid))
+ {
+ return idValue.Value;
+ }
+
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value.ToString();
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(System.Guid.Parse(reader.GetString()));
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Guid_implementations=12.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Guid_implementations=12.verified.txt
new file mode 100644
index 000000000..36506a1a1
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Guid_implementations=12.verified.txt
@@ -0,0 +1,98 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IComparable
+ {
+ public System.Guid Value { get; }
+
+ public MyTestId(System.Guid value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(System.Guid.NewGuid());
+ public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static explicit operator System.Guid(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(System.Guid value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ return value switch
+ {
+ System.Guid guidValue => new MyTestId(guidValue),
+ string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result),
+ _ => base.ConvertFrom(context, culture, value),
+ };
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(System.Guid))
+ {
+ return idValue.Value;
+ }
+
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value.ToString();
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(System.Guid.Parse(reader.GetString()));
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Guid_implementations=14.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Guid_implementations=14.verified.txt
new file mode 100644
index 000000000..698497a5a
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Guid_implementations=14.verified.txt
@@ -0,0 +1,98 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IComparable, System.IEquatable
+ {
+ public System.Guid Value { get; }
+
+ public MyTestId(System.Guid value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(System.Guid.NewGuid());
+ public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static explicit operator System.Guid(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(System.Guid value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ return value switch
+ {
+ System.Guid guidValue => new MyTestId(guidValue),
+ string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result),
+ _ => base.ConvertFrom(context, culture, value),
+ };
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(System.Guid))
+ {
+ return idValue.Value;
+ }
+
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value.ToString();
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(System.Guid.Parse(reader.GetString()));
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Guid_implementations=16.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Guid_implementations=16.verified.txt
new file mode 100644
index 000000000..cbebab567
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Guid_implementations=16.verified.txt
@@ -0,0 +1,97 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId
+ {
+ public System.Guid Value { get; }
+
+ public MyTestId(System.Guid value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(System.Guid.NewGuid());
+ public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static implicit operator System.Guid(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(System.Guid value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ return value switch
+ {
+ System.Guid guidValue => new MyTestId(guidValue),
+ string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result),
+ _ => base.ConvertFrom(context, culture, value),
+ };
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(System.Guid))
+ {
+ return idValue.Value;
+ }
+
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value.ToString();
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(System.Guid.Parse(reader.GetString()));
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Guid_implementations=18.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Guid_implementations=18.verified.txt
new file mode 100644
index 000000000..96186d703
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Guid_implementations=18.verified.txt
@@ -0,0 +1,97 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IEquatable
+ {
+ public System.Guid Value { get; }
+
+ public MyTestId(System.Guid value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(System.Guid.NewGuid());
+ public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static implicit operator System.Guid(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(System.Guid value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ return value switch
+ {
+ System.Guid guidValue => new MyTestId(guidValue),
+ string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result),
+ _ => base.ConvertFrom(context, culture, value),
+ };
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(System.Guid))
+ {
+ return idValue.Value;
+ }
+
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value.ToString();
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(System.Guid.Parse(reader.GetString()));
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Guid_implementations=20.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Guid_implementations=20.verified.txt
new file mode 100644
index 000000000..be2b016c1
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Guid_implementations=20.verified.txt
@@ -0,0 +1,98 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IComparable
+ {
+ public System.Guid Value { get; }
+
+ public MyTestId(System.Guid value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(System.Guid.NewGuid());
+ public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static implicit operator System.Guid(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(System.Guid value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ return value switch
+ {
+ System.Guid guidValue => new MyTestId(guidValue),
+ string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result),
+ _ => base.ConvertFrom(context, culture, value),
+ };
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(System.Guid))
+ {
+ return idValue.Value;
+ }
+
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value.ToString();
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(System.Guid.Parse(reader.GetString()));
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Guid_implementations=22.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Guid_implementations=22.verified.txt
new file mode 100644
index 000000000..8f56a8e39
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Guid_implementations=22.verified.txt
@@ -0,0 +1,98 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IComparable, System.IEquatable
+ {
+ public System.Guid Value { get; }
+
+ public MyTestId(System.Guid value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(System.Guid.NewGuid());
+ public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static implicit operator System.Guid(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(System.Guid value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ return value switch
+ {
+ System.Guid guidValue => new MyTestId(guidValue),
+ string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result),
+ _ => base.ConvertFrom(context, culture, value),
+ };
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(System.Guid))
+ {
+ return idValue.Value;
+ }
+
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value.ToString();
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(System.Guid.Parse(reader.GetString()));
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Guid_implementations=8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Guid_implementations=8.verified.txt
new file mode 100644
index 000000000..af2500b71
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Guid_implementations=8.verified.txt
@@ -0,0 +1,97 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId
+ {
+ public System.Guid Value { get; }
+
+ public MyTestId(System.Guid value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(System.Guid.NewGuid());
+ public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static explicit operator System.Guid(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(System.Guid value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ return value switch
+ {
+ System.Guid guidValue => new MyTestId(guidValue),
+ string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(result),
+ _ => base.ConvertFrom(context, culture, value),
+ };
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(System.Guid))
+ {
+ return idValue.Value;
+ }
+
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value.ToString();
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(System.Guid.Parse(reader.GetString()));
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Int_implementations=10.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Int_implementations=10.verified.txt
new file mode 100644
index 000000000..f8dab421f
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Int_implementations=10.verified.txt
@@ -0,0 +1,96 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IEquatable
+ {
+ public int Value { get; }
+
+ public MyTestId(int value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static explicit operator int(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(int value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ return value switch
+ {
+ int intValue => new MyTestId(intValue),
+ string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result),
+ _ => base.ConvertFrom(context, culture, value),
+ };
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(int))
+ {
+ return idValue.Value;
+ }
+
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value.ToString();
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetInt32());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteNumberValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Int_implementations=12.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Int_implementations=12.verified.txt
new file mode 100644
index 000000000..482771abb
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Int_implementations=12.verified.txt
@@ -0,0 +1,97 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IComparable
+ {
+ public int Value { get; }
+
+ public MyTestId(int value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static explicit operator int(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(int value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ return value switch
+ {
+ int intValue => new MyTestId(intValue),
+ string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result),
+ _ => base.ConvertFrom(context, culture, value),
+ };
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(int))
+ {
+ return idValue.Value;
+ }
+
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value.ToString();
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetInt32());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteNumberValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Int_implementations=14.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Int_implementations=14.verified.txt
new file mode 100644
index 000000000..20f2e8a2f
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Int_implementations=14.verified.txt
@@ -0,0 +1,97 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IComparable, System.IEquatable
+ {
+ public int Value { get; }
+
+ public MyTestId(int value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static explicit operator int(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(int value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ return value switch
+ {
+ int intValue => new MyTestId(intValue),
+ string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result),
+ _ => base.ConvertFrom(context, culture, value),
+ };
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(int))
+ {
+ return idValue.Value;
+ }
+
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value.ToString();
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetInt32());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteNumberValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Int_implementations=16.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Int_implementations=16.verified.txt
new file mode 100644
index 000000000..044b45204
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Int_implementations=16.verified.txt
@@ -0,0 +1,96 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId
+ {
+ public int Value { get; }
+
+ public MyTestId(int value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static implicit operator int(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(int value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ return value switch
+ {
+ int intValue => new MyTestId(intValue),
+ string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result),
+ _ => base.ConvertFrom(context, culture, value),
+ };
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(int))
+ {
+ return idValue.Value;
+ }
+
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value.ToString();
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetInt32());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteNumberValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Int_implementations=18.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Int_implementations=18.verified.txt
new file mode 100644
index 000000000..e5496b2bc
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Int_implementations=18.verified.txt
@@ -0,0 +1,96 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IEquatable
+ {
+ public int Value { get; }
+
+ public MyTestId(int value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static implicit operator int(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(int value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ return value switch
+ {
+ int intValue => new MyTestId(intValue),
+ string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result),
+ _ => base.ConvertFrom(context, culture, value),
+ };
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(int))
+ {
+ return idValue.Value;
+ }
+
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value.ToString();
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetInt32());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteNumberValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Int_implementations=20.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Int_implementations=20.verified.txt
new file mode 100644
index 000000000..227337268
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Int_implementations=20.verified.txt
@@ -0,0 +1,97 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IComparable
+ {
+ public int Value { get; }
+
+ public MyTestId(int value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static implicit operator int(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(int value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ return value switch
+ {
+ int intValue => new MyTestId(intValue),
+ string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result),
+ _ => base.ConvertFrom(context, culture, value),
+ };
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(int))
+ {
+ return idValue.Value;
+ }
+
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value.ToString();
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetInt32());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteNumberValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Int_implementations=22.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Int_implementations=22.verified.txt
new file mode 100644
index 000000000..5cc7da999
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Int_implementations=22.verified.txt
@@ -0,0 +1,97 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IComparable, System.IEquatable
+ {
+ public int Value { get; }
+
+ public MyTestId(int value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static implicit operator int(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(int value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ return value switch
+ {
+ int intValue => new MyTestId(intValue),
+ string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result),
+ _ => base.ConvertFrom(context, culture, value),
+ };
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(int))
+ {
+ return idValue.Value;
+ }
+
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value.ToString();
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetInt32());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteNumberValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Int_implementations=8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Int_implementations=8.verified.txt
new file mode 100644
index 000000000..9cfdab794
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Int_implementations=8.verified.txt
@@ -0,0 +1,96 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId
+ {
+ public int Value { get; }
+
+ public MyTestId(int value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static explicit operator int(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(int value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ return value switch
+ {
+ int intValue => new MyTestId(intValue),
+ string stringValue when !string.IsNullOrEmpty(stringValue) && int.TryParse(stringValue, out var result) => new MyTestId(result),
+ _ => base.ConvertFrom(context, culture, value),
+ };
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(int) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(int))
+ {
+ return idValue.Value;
+ }
+
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value.ToString();
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetInt32());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteNumberValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Long_implementations=10.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Long_implementations=10.verified.txt
new file mode 100644
index 000000000..909744a4b
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Long_implementations=10.verified.txt
@@ -0,0 +1,98 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IEquatable
+ {
+ public long Value { get; }
+
+ public MyTestId(long value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static explicit operator long(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(long value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ return value switch
+ {
+ long longValue => new MyTestId(longValue),
+ int intValue => new MyTestId(intValue),
+ short shortValue => new MyTestId(shortValue),
+ string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result),
+ _ => base.ConvertFrom(context, culture, value),
+ };
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(long))
+ {
+ return idValue.Value;
+ }
+
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value.ToString();
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetInt64());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteNumberValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Long_implementations=12.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Long_implementations=12.verified.txt
new file mode 100644
index 000000000..16490dccb
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Long_implementations=12.verified.txt
@@ -0,0 +1,99 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IComparable
+ {
+ public long Value { get; }
+
+ public MyTestId(long value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static explicit operator long(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(long value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ return value switch
+ {
+ long longValue => new MyTestId(longValue),
+ int intValue => new MyTestId(intValue),
+ short shortValue => new MyTestId(shortValue),
+ string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result),
+ _ => base.ConvertFrom(context, culture, value),
+ };
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(long))
+ {
+ return idValue.Value;
+ }
+
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value.ToString();
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetInt64());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteNumberValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Long_implementations=14.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Long_implementations=14.verified.txt
new file mode 100644
index 000000000..3e307fe09
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Long_implementations=14.verified.txt
@@ -0,0 +1,99 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IComparable, System.IEquatable
+ {
+ public long Value { get; }
+
+ public MyTestId(long value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static explicit operator long(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(long value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ return value switch
+ {
+ long longValue => new MyTestId(longValue),
+ int intValue => new MyTestId(intValue),
+ short shortValue => new MyTestId(shortValue),
+ string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result),
+ _ => base.ConvertFrom(context, culture, value),
+ };
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(long))
+ {
+ return idValue.Value;
+ }
+
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value.ToString();
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetInt64());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteNumberValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Long_implementations=16.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Long_implementations=16.verified.txt
new file mode 100644
index 000000000..da559088b
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Long_implementations=16.verified.txt
@@ -0,0 +1,98 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId
+ {
+ public long Value { get; }
+
+ public MyTestId(long value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static implicit operator long(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(long value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ return value switch
+ {
+ long longValue => new MyTestId(longValue),
+ int intValue => new MyTestId(intValue),
+ short shortValue => new MyTestId(shortValue),
+ string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result),
+ _ => base.ConvertFrom(context, culture, value),
+ };
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(long))
+ {
+ return idValue.Value;
+ }
+
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value.ToString();
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetInt64());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteNumberValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Long_implementations=18.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Long_implementations=18.verified.txt
new file mode 100644
index 000000000..b0493c99d
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Long_implementations=18.verified.txt
@@ -0,0 +1,98 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IEquatable
+ {
+ public long Value { get; }
+
+ public MyTestId(long value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static implicit operator long(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(long value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ return value switch
+ {
+ long longValue => new MyTestId(longValue),
+ int intValue => new MyTestId(intValue),
+ short shortValue => new MyTestId(shortValue),
+ string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result),
+ _ => base.ConvertFrom(context, culture, value),
+ };
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(long))
+ {
+ return idValue.Value;
+ }
+
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value.ToString();
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetInt64());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteNumberValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Long_implementations=20.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Long_implementations=20.verified.txt
new file mode 100644
index 000000000..4b4d4e61d
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Long_implementations=20.verified.txt
@@ -0,0 +1,99 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IComparable
+ {
+ public long Value { get; }
+
+ public MyTestId(long value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static implicit operator long(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(long value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ return value switch
+ {
+ long longValue => new MyTestId(longValue),
+ int intValue => new MyTestId(intValue),
+ short shortValue => new MyTestId(shortValue),
+ string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result),
+ _ => base.ConvertFrom(context, culture, value),
+ };
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(long))
+ {
+ return idValue.Value;
+ }
+
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value.ToString();
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetInt64());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteNumberValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Long_implementations=22.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Long_implementations=22.verified.txt
new file mode 100644
index 000000000..d819ced76
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Long_implementations=22.verified.txt
@@ -0,0 +1,99 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IComparable, System.IEquatable
+ {
+ public long Value { get; }
+
+ public MyTestId(long value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static implicit operator long(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(long value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ return value switch
+ {
+ long longValue => new MyTestId(longValue),
+ int intValue => new MyTestId(intValue),
+ short shortValue => new MyTestId(shortValue),
+ string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result),
+ _ => base.ConvertFrom(context, culture, value),
+ };
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(long))
+ {
+ return idValue.Value;
+ }
+
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value.ToString();
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetInt64());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteNumberValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Long_implementations=8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Long_implementations=8.verified.txt
new file mode 100644
index 000000000..eaadbb4b4
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=Long_implementations=8.verified.txt
@@ -0,0 +1,98 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId
+ {
+ public long Value { get; }
+
+ public MyTestId(long value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static explicit operator long(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(long value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(long) || sourceType == typeof(int) || sourceType == typeof(short) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ return value switch
+ {
+ long longValue => new MyTestId(longValue),
+ int intValue => new MyTestId(intValue),
+ short shortValue => new MyTestId(shortValue),
+ string stringValue when !string.IsNullOrEmpty(stringValue) && long.TryParse(stringValue, out var result) => new MyTestId(result),
+ _ => base.ConvertFrom(context, culture, value),
+ };
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(long) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(long))
+ {
+ return idValue.Value;
+ }
+
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value.ToString();
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetInt64());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteNumberValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=MassTransitNewId_implementations=10.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=MassTransitNewId_implementations=10.verified.txt
new file mode 100644
index 000000000..7d6c17a07
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=MassTransitNewId_implementations=10.verified.txt
@@ -0,0 +1,105 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IEquatable
+ {
+ public MassTransit.NewId Value { get; }
+
+ public MyTestId(MassTransit.NewId value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(MassTransit.NewId.Next());
+ public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static explicit operator MassTransit.NewId(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(MassTransit.NewId value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) ||
+ sourceType == typeof(string) || base.CanConvertFrom
+ (context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ return value switch
+ {
+ MassTransit.NewId newIdValue => new MyTestId(newIdValue),
+ System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)),
+ string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)),
+ _ => base.ConvertFrom(context, culture, value),
+ };
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(MassTransit.NewId))
+ {
+ return idValue.Value;
+ }
+
+ if (destinationType == typeof(System.Guid))
+ {
+ return idValue.Value.ToGuid();
+ }
+
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value.ToGuid().ToString();
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid()));
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value.ToGuid());
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=MassTransitNewId_implementations=12.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=MassTransitNewId_implementations=12.verified.txt
new file mode 100644
index 000000000..f561d21f6
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=MassTransitNewId_implementations=12.verified.txt
@@ -0,0 +1,106 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IComparable
+ {
+ public MassTransit.NewId Value { get; }
+
+ public MyTestId(MassTransit.NewId value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(MassTransit.NewId.Next());
+ public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static explicit operator MassTransit.NewId(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(MassTransit.NewId value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) ||
+ sourceType == typeof(string) || base.CanConvertFrom
+ (context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ return value switch
+ {
+ MassTransit.NewId newIdValue => new MyTestId(newIdValue),
+ System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)),
+ string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)),
+ _ => base.ConvertFrom(context, culture, value),
+ };
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(MassTransit.NewId))
+ {
+ return idValue.Value;
+ }
+
+ if (destinationType == typeof(System.Guid))
+ {
+ return idValue.Value.ToGuid();
+ }
+
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value.ToGuid().ToString();
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid()));
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value.ToGuid());
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=MassTransitNewId_implementations=14.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=MassTransitNewId_implementations=14.verified.txt
new file mode 100644
index 000000000..6062892de
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=MassTransitNewId_implementations=14.verified.txt
@@ -0,0 +1,106 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IComparable, System.IEquatable
+ {
+ public MassTransit.NewId Value { get; }
+
+ public MyTestId(MassTransit.NewId value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(MassTransit.NewId.Next());
+ public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static explicit operator MassTransit.NewId(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(MassTransit.NewId value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) ||
+ sourceType == typeof(string) || base.CanConvertFrom
+ (context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ return value switch
+ {
+ MassTransit.NewId newIdValue => new MyTestId(newIdValue),
+ System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)),
+ string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)),
+ _ => base.ConvertFrom(context, culture, value),
+ };
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(MassTransit.NewId))
+ {
+ return idValue.Value;
+ }
+
+ if (destinationType == typeof(System.Guid))
+ {
+ return idValue.Value.ToGuid();
+ }
+
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value.ToGuid().ToString();
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid()));
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value.ToGuid());
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=MassTransitNewId_implementations=16.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=MassTransitNewId_implementations=16.verified.txt
new file mode 100644
index 000000000..16822ed52
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=MassTransitNewId_implementations=16.verified.txt
@@ -0,0 +1,105 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId
+ {
+ public MassTransit.NewId Value { get; }
+
+ public MyTestId(MassTransit.NewId value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(MassTransit.NewId.Next());
+ public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static implicit operator MassTransit.NewId(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(MassTransit.NewId value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) ||
+ sourceType == typeof(string) || base.CanConvertFrom
+ (context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ return value switch
+ {
+ MassTransit.NewId newIdValue => new MyTestId(newIdValue),
+ System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)),
+ string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)),
+ _ => base.ConvertFrom(context, culture, value),
+ };
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(MassTransit.NewId))
+ {
+ return idValue.Value;
+ }
+
+ if (destinationType == typeof(System.Guid))
+ {
+ return idValue.Value.ToGuid();
+ }
+
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value.ToGuid().ToString();
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid()));
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value.ToGuid());
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=MassTransitNewId_implementations=18.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=MassTransitNewId_implementations=18.verified.txt
new file mode 100644
index 000000000..917962c83
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=MassTransitNewId_implementations=18.verified.txt
@@ -0,0 +1,105 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IEquatable
+ {
+ public MassTransit.NewId Value { get; }
+
+ public MyTestId(MassTransit.NewId value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(MassTransit.NewId.Next());
+ public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static implicit operator MassTransit.NewId(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(MassTransit.NewId value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) ||
+ sourceType == typeof(string) || base.CanConvertFrom
+ (context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ return value switch
+ {
+ MassTransit.NewId newIdValue => new MyTestId(newIdValue),
+ System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)),
+ string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)),
+ _ => base.ConvertFrom(context, culture, value),
+ };
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(MassTransit.NewId))
+ {
+ return idValue.Value;
+ }
+
+ if (destinationType == typeof(System.Guid))
+ {
+ return idValue.Value.ToGuid();
+ }
+
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value.ToGuid().ToString();
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid()));
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value.ToGuid());
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=MassTransitNewId_implementations=20.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=MassTransitNewId_implementations=20.verified.txt
new file mode 100644
index 000000000..dede41964
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=MassTransitNewId_implementations=20.verified.txt
@@ -0,0 +1,106 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IComparable
+ {
+ public MassTransit.NewId Value { get; }
+
+ public MyTestId(MassTransit.NewId value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(MassTransit.NewId.Next());
+ public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static implicit operator MassTransit.NewId(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(MassTransit.NewId value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) ||
+ sourceType == typeof(string) || base.CanConvertFrom
+ (context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ return value switch
+ {
+ MassTransit.NewId newIdValue => new MyTestId(newIdValue),
+ System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)),
+ string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)),
+ _ => base.ConvertFrom(context, culture, value),
+ };
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(MassTransit.NewId))
+ {
+ return idValue.Value;
+ }
+
+ if (destinationType == typeof(System.Guid))
+ {
+ return idValue.Value.ToGuid();
+ }
+
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value.ToGuid().ToString();
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid()));
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value.ToGuid());
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=MassTransitNewId_implementations=22.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=MassTransitNewId_implementations=22.verified.txt
new file mode 100644
index 000000000..37a46a6f1
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=MassTransitNewId_implementations=22.verified.txt
@@ -0,0 +1,106 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IComparable, System.IEquatable
+ {
+ public MassTransit.NewId Value { get; }
+
+ public MyTestId(MassTransit.NewId value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(MassTransit.NewId.Next());
+ public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static implicit operator MassTransit.NewId(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(MassTransit.NewId value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) ||
+ sourceType == typeof(string) || base.CanConvertFrom
+ (context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ return value switch
+ {
+ MassTransit.NewId newIdValue => new MyTestId(newIdValue),
+ System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)),
+ string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)),
+ _ => base.ConvertFrom(context, culture, value),
+ };
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(MassTransit.NewId))
+ {
+ return idValue.Value;
+ }
+
+ if (destinationType == typeof(System.Guid))
+ {
+ return idValue.Value.ToGuid();
+ }
+
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value.ToGuid().ToString();
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid()));
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value.ToGuid());
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=MassTransitNewId_implementations=8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=MassTransitNewId_implementations=8.verified.txt
new file mode 100644
index 000000000..5af3956ba
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=MassTransitNewId_implementations=8.verified.txt
@@ -0,0 +1,105 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId
+ {
+ public MassTransit.NewId Value { get; }
+
+ public MyTestId(MassTransit.NewId value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(MassTransit.NewId.Next());
+ public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static explicit operator MassTransit.NewId(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(MassTransit.NewId value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) ||
+ sourceType == typeof(string) || base.CanConvertFrom
+ (context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ return value switch
+ {
+ MassTransit.NewId newIdValue => new MyTestId(newIdValue),
+ System.Guid guidValue => new MyTestId(MassTransit.NewId.FromGuid(guidValue)),
+ string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyTestId(MassTransit.NewId.FromGuid(result)),
+ _ => base.ConvertFrom(context, culture, value),
+ };
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(System.Guid) || sourceType == typeof(MassTransit.NewId) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(MassTransit.NewId))
+ {
+ return idValue.Value;
+ }
+
+ if (destinationType == typeof(System.Guid))
+ {
+ return idValue.Value.ToGuid();
+ }
+
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value.ToGuid().ToString();
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid()));
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value.ToGuid());
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=NullableString_implementations=10.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=NullableString_implementations=10.verified.txt
new file mode 100644
index 000000000..901f3116a
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=NullableString_implementations=10.verified.txt
@@ -0,0 +1,113 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+#nullable enable
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IEquatable
+ {
+ public string? Value { get; }
+
+ public MyTestId(string? value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(string.Empty);
+
+ public bool Equals(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => true,
+ (null, _) => false,
+ (_, null) => false,
+ (_, _) => Value.Equals(other.Value),
+ };
+ }
+ public override bool Equals(object? obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value?.GetHashCode() ?? 0;
+ public override string? ToString() => Value;
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static explicit operator string?(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(string? value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType)
+ {
+ return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value)
+ {
+ if (value is null)
+ {
+ return new MyTestId(null);
+ }
+
+ var stringValue = value as string;
+ if (stringValue is not null)
+ {
+ return new MyTestId(stringValue);
+ }
+
+ return base.ConvertFrom(context, culture, value);
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType)
+ {
+ return sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value;
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetString());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ if (value.Value is null)
+ {
+ writer.WriteNullValue();
+ }
+ else
+ {
+ writer.WriteStringValue(value.Value);
+ }
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=NullableString_implementations=12.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=NullableString_implementations=12.verified.txt
new file mode 100644
index 000000000..10b92ebdb
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=NullableString_implementations=12.verified.txt
@@ -0,0 +1,123 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+#nullable enable
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IComparable
+ {
+ public string? Value { get; }
+
+ public MyTestId(string? value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(string.Empty);
+
+ public bool Equals(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => true,
+ (null, _) => false,
+ (_, null) => false,
+ (_, _) => Value.Equals(other.Value),
+ };
+ }
+ public override bool Equals(object? obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value?.GetHashCode() ?? 0;
+ public override string? ToString() => Value;
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => 0,
+ (null, _) => -1,
+ (_, null) => 1,
+ (_, _) => Value.CompareTo(other.Value),
+ };
+ }
+ public static explicit operator string?(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(string? value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType)
+ {
+ return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value)
+ {
+ if (value is null)
+ {
+ return new MyTestId(null);
+ }
+
+ var stringValue = value as string;
+ if (stringValue is not null)
+ {
+ return new MyTestId(stringValue);
+ }
+
+ return base.ConvertFrom(context, culture, value);
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType)
+ {
+ return sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value;
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetString());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ if (value.Value is null)
+ {
+ writer.WriteNullValue();
+ }
+ else
+ {
+ writer.WriteStringValue(value.Value);
+ }
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=NullableString_implementations=14.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=NullableString_implementations=14.verified.txt
new file mode 100644
index 000000000..4e5733da5
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=NullableString_implementations=14.verified.txt
@@ -0,0 +1,123 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+#nullable enable
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IComparable, System.IEquatable
+ {
+ public string? Value { get; }
+
+ public MyTestId(string? value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(string.Empty);
+
+ public bool Equals(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => true,
+ (null, _) => false,
+ (_, null) => false,
+ (_, _) => Value.Equals(other.Value),
+ };
+ }
+ public override bool Equals(object? obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value?.GetHashCode() ?? 0;
+ public override string? ToString() => Value;
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => 0,
+ (null, _) => -1,
+ (_, null) => 1,
+ (_, _) => Value.CompareTo(other.Value),
+ };
+ }
+ public static explicit operator string?(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(string? value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType)
+ {
+ return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value)
+ {
+ if (value is null)
+ {
+ return new MyTestId(null);
+ }
+
+ var stringValue = value as string;
+ if (stringValue is not null)
+ {
+ return new MyTestId(stringValue);
+ }
+
+ return base.ConvertFrom(context, culture, value);
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType)
+ {
+ return sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value;
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetString());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ if (value.Value is null)
+ {
+ writer.WriteNullValue();
+ }
+ else
+ {
+ writer.WriteStringValue(value.Value);
+ }
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=NullableString_implementations=16.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=NullableString_implementations=16.verified.txt
new file mode 100644
index 000000000..e35d02268
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=NullableString_implementations=16.verified.txt
@@ -0,0 +1,113 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+#nullable enable
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId
+ {
+ public string? Value { get; }
+
+ public MyTestId(string? value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(string.Empty);
+
+ public bool Equals(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => true,
+ (null, _) => false,
+ (_, null) => false,
+ (_, _) => Value.Equals(other.Value),
+ };
+ }
+ public override bool Equals(object? obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value?.GetHashCode() ?? 0;
+ public override string? ToString() => Value;
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static implicit operator string?(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(string? value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType)
+ {
+ return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value)
+ {
+ if (value is null)
+ {
+ return new MyTestId(null);
+ }
+
+ var stringValue = value as string;
+ if (stringValue is not null)
+ {
+ return new MyTestId(stringValue);
+ }
+
+ return base.ConvertFrom(context, culture, value);
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType)
+ {
+ return sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value;
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetString());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ if (value.Value is null)
+ {
+ writer.WriteNullValue();
+ }
+ else
+ {
+ writer.WriteStringValue(value.Value);
+ }
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=NullableString_implementations=18.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=NullableString_implementations=18.verified.txt
new file mode 100644
index 000000000..8d557b33e
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=NullableString_implementations=18.verified.txt
@@ -0,0 +1,113 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+#nullable enable
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IEquatable
+ {
+ public string? Value { get; }
+
+ public MyTestId(string? value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(string.Empty);
+
+ public bool Equals(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => true,
+ (null, _) => false,
+ (_, null) => false,
+ (_, _) => Value.Equals(other.Value),
+ };
+ }
+ public override bool Equals(object? obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value?.GetHashCode() ?? 0;
+ public override string? ToString() => Value;
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static implicit operator string?(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(string? value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType)
+ {
+ return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value)
+ {
+ if (value is null)
+ {
+ return new MyTestId(null);
+ }
+
+ var stringValue = value as string;
+ if (stringValue is not null)
+ {
+ return new MyTestId(stringValue);
+ }
+
+ return base.ConvertFrom(context, culture, value);
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType)
+ {
+ return sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value;
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetString());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ if (value.Value is null)
+ {
+ writer.WriteNullValue();
+ }
+ else
+ {
+ writer.WriteStringValue(value.Value);
+ }
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=NullableString_implementations=20.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=NullableString_implementations=20.verified.txt
new file mode 100644
index 000000000..08799149c
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=NullableString_implementations=20.verified.txt
@@ -0,0 +1,123 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+#nullable enable
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IComparable
+ {
+ public string? Value { get; }
+
+ public MyTestId(string? value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(string.Empty);
+
+ public bool Equals(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => true,
+ (null, _) => false,
+ (_, null) => false,
+ (_, _) => Value.Equals(other.Value),
+ };
+ }
+ public override bool Equals(object? obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value?.GetHashCode() ?? 0;
+ public override string? ToString() => Value;
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => 0,
+ (null, _) => -1,
+ (_, null) => 1,
+ (_, _) => Value.CompareTo(other.Value),
+ };
+ }
+ public static implicit operator string?(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(string? value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType)
+ {
+ return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value)
+ {
+ if (value is null)
+ {
+ return new MyTestId(null);
+ }
+
+ var stringValue = value as string;
+ if (stringValue is not null)
+ {
+ return new MyTestId(stringValue);
+ }
+
+ return base.ConvertFrom(context, culture, value);
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType)
+ {
+ return sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value;
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetString());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ if (value.Value is null)
+ {
+ writer.WriteNullValue();
+ }
+ else
+ {
+ writer.WriteStringValue(value.Value);
+ }
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=NullableString_implementations=22.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=NullableString_implementations=22.verified.txt
new file mode 100644
index 000000000..207158bec
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=NullableString_implementations=22.verified.txt
@@ -0,0 +1,123 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+#nullable enable
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IComparable, System.IEquatable
+ {
+ public string? Value { get; }
+
+ public MyTestId(string? value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(string.Empty);
+
+ public bool Equals(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => true,
+ (null, _) => false,
+ (_, null) => false,
+ (_, _) => Value.Equals(other.Value),
+ };
+ }
+ public override bool Equals(object? obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value?.GetHashCode() ?? 0;
+ public override string? ToString() => Value;
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => 0,
+ (null, _) => -1,
+ (_, null) => 1,
+ (_, _) => Value.CompareTo(other.Value),
+ };
+ }
+ public static implicit operator string?(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(string? value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType)
+ {
+ return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value)
+ {
+ if (value is null)
+ {
+ return new MyTestId(null);
+ }
+
+ var stringValue = value as string;
+ if (stringValue is not null)
+ {
+ return new MyTestId(stringValue);
+ }
+
+ return base.ConvertFrom(context, culture, value);
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType)
+ {
+ return sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value;
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetString());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ if (value.Value is null)
+ {
+ writer.WriteNullValue();
+ }
+ else
+ {
+ writer.WriteStringValue(value.Value);
+ }
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=NullableString_implementations=8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=NullableString_implementations=8.verified.txt
new file mode 100644
index 000000000..241d3a24e
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=NullableString_implementations=8.verified.txt
@@ -0,0 +1,113 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+#nullable enable
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId
+ {
+ public string? Value { get; }
+
+ public MyTestId(string? value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(string.Empty);
+
+ public bool Equals(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => true,
+ (null, _) => false,
+ (_, null) => false,
+ (_, _) => Value.Equals(other.Value),
+ };
+ }
+ public override bool Equals(object? obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value?.GetHashCode() ?? 0;
+ public override string? ToString() => Value;
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static explicit operator string?(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(string? value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Type sourceType)
+ {
+ return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object? ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value)
+ {
+ if (value is null)
+ {
+ return new MyTestId(null);
+ }
+
+ var stringValue = value as string;
+ if (stringValue is not null)
+ {
+ return new MyTestId(stringValue);
+ }
+
+ return base.ConvertFrom(context, culture, value);
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? sourceType)
+ {
+ return sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object? ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value;
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetString());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ if (value.Value is null)
+ {
+ writer.WriteNullValue();
+ }
+ else
+ {
+ writer.WriteStringValue(value.Value);
+ }
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=String_implementations=10.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=String_implementations=10.verified.txt
new file mode 100644
index 000000000..4c65b0129
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=String_implementations=10.verified.txt
@@ -0,0 +1,101 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IEquatable
+ {
+ public string Value { get; }
+
+ public MyTestId(string value)
+ {
+ Value = value ?? throw new System.ArgumentNullException(nameof(value));
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(string.Empty);
+
+ public bool Equals(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => true,
+ (null, _) => false,
+ (_, null) => false,
+ (_, _) => Value.Equals(other.Value),
+ };
+ }
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value;
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static explicit operator string(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(string value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ var stringValue = value as string;
+ if (stringValue is not null)
+ {
+ return new MyTestId(stringValue);
+ }
+
+ return base.ConvertFrom(context, culture, value);
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value;
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetString());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=String_implementations=12.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=String_implementations=12.verified.txt
new file mode 100644
index 000000000..792223b9d
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=String_implementations=12.verified.txt
@@ -0,0 +1,111 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IComparable
+ {
+ public string Value { get; }
+
+ public MyTestId(string value)
+ {
+ Value = value ?? throw new System.ArgumentNullException(nameof(value));
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(string.Empty);
+
+ public bool Equals(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => true,
+ (null, _) => false,
+ (_, null) => false,
+ (_, _) => Value.Equals(other.Value),
+ };
+ }
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value;
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => 0,
+ (null, _) => -1,
+ (_, null) => 1,
+ (_, _) => Value.CompareTo(other.Value),
+ };
+ }
+ public static explicit operator string(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(string value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ var stringValue = value as string;
+ if (stringValue is not null)
+ {
+ return new MyTestId(stringValue);
+ }
+
+ return base.ConvertFrom(context, culture, value);
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value;
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetString());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=String_implementations=14.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=String_implementations=14.verified.txt
new file mode 100644
index 000000000..ec4faf197
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=String_implementations=14.verified.txt
@@ -0,0 +1,111 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IComparable, System.IEquatable
+ {
+ public string Value { get; }
+
+ public MyTestId(string value)
+ {
+ Value = value ?? throw new System.ArgumentNullException(nameof(value));
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(string.Empty);
+
+ public bool Equals(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => true,
+ (null, _) => false,
+ (_, null) => false,
+ (_, _) => Value.Equals(other.Value),
+ };
+ }
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value;
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => 0,
+ (null, _) => -1,
+ (_, null) => 1,
+ (_, _) => Value.CompareTo(other.Value),
+ };
+ }
+ public static explicit operator string(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(string value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ var stringValue = value as string;
+ if (stringValue is not null)
+ {
+ return new MyTestId(stringValue);
+ }
+
+ return base.ConvertFrom(context, culture, value);
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value;
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetString());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=String_implementations=16.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=String_implementations=16.verified.txt
new file mode 100644
index 000000000..e1955a3b7
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=String_implementations=16.verified.txt
@@ -0,0 +1,101 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId
+ {
+ public string Value { get; }
+
+ public MyTestId(string value)
+ {
+ Value = value ?? throw new System.ArgumentNullException(nameof(value));
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(string.Empty);
+
+ public bool Equals(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => true,
+ (null, _) => false,
+ (_, null) => false,
+ (_, _) => Value.Equals(other.Value),
+ };
+ }
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value;
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static implicit operator string(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(string value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ var stringValue = value as string;
+ if (stringValue is not null)
+ {
+ return new MyTestId(stringValue);
+ }
+
+ return base.ConvertFrom(context, culture, value);
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value;
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetString());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=String_implementations=18.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=String_implementations=18.verified.txt
new file mode 100644
index 000000000..f32187d5f
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=String_implementations=18.verified.txt
@@ -0,0 +1,101 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IEquatable
+ {
+ public string Value { get; }
+
+ public MyTestId(string value)
+ {
+ Value = value ?? throw new System.ArgumentNullException(nameof(value));
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(string.Empty);
+
+ public bool Equals(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => true,
+ (null, _) => false,
+ (_, null) => false,
+ (_, _) => Value.Equals(other.Value),
+ };
+ }
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value;
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static implicit operator string(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(string value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ var stringValue = value as string;
+ if (stringValue is not null)
+ {
+ return new MyTestId(stringValue);
+ }
+
+ return base.ConvertFrom(context, culture, value);
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value;
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetString());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=String_implementations=20.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=String_implementations=20.verified.txt
new file mode 100644
index 000000000..d9e19bbe9
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=String_implementations=20.verified.txt
@@ -0,0 +1,111 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IComparable
+ {
+ public string Value { get; }
+
+ public MyTestId(string value)
+ {
+ Value = value ?? throw new System.ArgumentNullException(nameof(value));
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(string.Empty);
+
+ public bool Equals(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => true,
+ (null, _) => false,
+ (_, null) => false,
+ (_, _) => Value.Equals(other.Value),
+ };
+ }
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value;
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => 0,
+ (null, _) => -1,
+ (_, null) => 1,
+ (_, _) => Value.CompareTo(other.Value),
+ };
+ }
+ public static implicit operator string(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(string value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ var stringValue = value as string;
+ if (stringValue is not null)
+ {
+ return new MyTestId(stringValue);
+ }
+
+ return base.ConvertFrom(context, culture, value);
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value;
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetString());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=String_implementations=22.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=String_implementations=22.verified.txt
new file mode 100644
index 000000000..3203783b6
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=String_implementations=22.verified.txt
@@ -0,0 +1,111 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId : System.IComparable, System.IEquatable
+ {
+ public string Value { get; }
+
+ public MyTestId(string value)
+ {
+ Value = value ?? throw new System.ArgumentNullException(nameof(value));
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(string.Empty);
+
+ public bool Equals(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => true,
+ (null, _) => false,
+ (_, null) => false,
+ (_, _) => Value.Equals(other.Value),
+ };
+ }
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value;
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => 0,
+ (null, _) => -1,
+ (_, null) => 1,
+ (_, _) => Value.CompareTo(other.Value),
+ };
+ }
+ public static implicit operator string(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(string value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ var stringValue = value as string;
+ if (stringValue is not null)
+ {
+ return new MyTestId(stringValue);
+ }
+
+ return base.ConvertFrom(context, culture, value);
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value;
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetString());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=String_implementations=8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=String_implementations=8.verified.txt
new file mode 100644
index 000000000..5c033fe86
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=10_backingType=String_implementations=8.verified.txt
@@ -0,0 +1,101 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ [System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
+ readonly partial struct MyTestId
+ {
+ public string Value { get; }
+
+ public MyTestId(string value)
+ {
+ Value = value ?? throw new System.ArgumentNullException(nameof(value));
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(string.Empty);
+
+ public bool Equals(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => true,
+ (null, _) => false,
+ (_, null) => false,
+ (_, _) => Value.Equals(other.Value),
+ };
+ }
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value;
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static explicit operator string(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(string value) => new(value);
+
+ class MyTestIdTypeConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ var stringValue = value as string;
+ if (stringValue is not null)
+ {
+ return new MyTestId(stringValue);
+ }
+
+ return base.ConvertFrom(context, culture, value);
+ }
+
+ public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
+ {
+ return sourceType == typeof(string) || base.CanConvertTo(context, sourceType);
+ }
+
+ public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
+ {
+ if (value is MyTestId idValue)
+ {
+ if (destinationType == typeof(string))
+ {
+ return idValue.Value;
+ }
+ }
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetString());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Guid_implementations=10.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Guid_implementations=10.verified.txt
new file mode 100644
index 000000000..11634e817
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Guid_implementations=10.verified.txt
@@ -0,0 +1,76 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))]
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ readonly partial struct MyTestId : System.IEquatable
+ {
+ public System.Guid Value { get; }
+
+ public MyTestId(System.Guid value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(System.Guid.NewGuid());
+ public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static explicit operator System.Guid(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(System.Guid value) => new(value);
+
+ class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter
+ {
+ public override bool CanConvert(System.Type objectType)
+ {
+ return objectType == typeof(MyTestId);
+ }
+
+ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var id = (MyTestId)value;
+ serializer.Serialize(writer, id.Value);
+ }
+
+ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var guid = serializer.Deserialize(reader);
+ return guid.HasValue ? new MyTestId(guid.Value) : null;
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(System.Guid.Parse(reader.GetString()));
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Guid_implementations=12.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Guid_implementations=12.verified.txt
new file mode 100644
index 000000000..be8d7dbeb
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Guid_implementations=12.verified.txt
@@ -0,0 +1,77 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))]
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ readonly partial struct MyTestId : System.IComparable
+ {
+ public System.Guid Value { get; }
+
+ public MyTestId(System.Guid value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(System.Guid.NewGuid());
+ public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static explicit operator System.Guid(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(System.Guid value) => new(value);
+
+ class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter
+ {
+ public override bool CanConvert(System.Type objectType)
+ {
+ return objectType == typeof(MyTestId);
+ }
+
+ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var id = (MyTestId)value;
+ serializer.Serialize(writer, id.Value);
+ }
+
+ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var guid = serializer.Deserialize(reader);
+ return guid.HasValue ? new MyTestId(guid.Value) : null;
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(System.Guid.Parse(reader.GetString()));
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Guid_implementations=14.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Guid_implementations=14.verified.txt
new file mode 100644
index 000000000..b4b3555e9
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Guid_implementations=14.verified.txt
@@ -0,0 +1,77 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))]
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ readonly partial struct MyTestId : System.IComparable, System.IEquatable
+ {
+ public System.Guid Value { get; }
+
+ public MyTestId(System.Guid value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(System.Guid.NewGuid());
+ public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static explicit operator System.Guid(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(System.Guid value) => new(value);
+
+ class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter
+ {
+ public override bool CanConvert(System.Type objectType)
+ {
+ return objectType == typeof(MyTestId);
+ }
+
+ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var id = (MyTestId)value;
+ serializer.Serialize(writer, id.Value);
+ }
+
+ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var guid = serializer.Deserialize(reader);
+ return guid.HasValue ? new MyTestId(guid.Value) : null;
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(System.Guid.Parse(reader.GetString()));
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Guid_implementations=16.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Guid_implementations=16.verified.txt
new file mode 100644
index 000000000..47d53f563
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Guid_implementations=16.verified.txt
@@ -0,0 +1,76 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))]
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ readonly partial struct MyTestId
+ {
+ public System.Guid Value { get; }
+
+ public MyTestId(System.Guid value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(System.Guid.NewGuid());
+ public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static implicit operator System.Guid(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(System.Guid value) => new(value);
+
+ class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter
+ {
+ public override bool CanConvert(System.Type objectType)
+ {
+ return objectType == typeof(MyTestId);
+ }
+
+ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var id = (MyTestId)value;
+ serializer.Serialize(writer, id.Value);
+ }
+
+ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var guid = serializer.Deserialize(reader);
+ return guid.HasValue ? new MyTestId(guid.Value) : null;
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(System.Guid.Parse(reader.GetString()));
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Guid_implementations=18.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Guid_implementations=18.verified.txt
new file mode 100644
index 000000000..46790ef19
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Guid_implementations=18.verified.txt
@@ -0,0 +1,76 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))]
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ readonly partial struct MyTestId : System.IEquatable
+ {
+ public System.Guid Value { get; }
+
+ public MyTestId(System.Guid value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(System.Guid.NewGuid());
+ public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static implicit operator System.Guid(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(System.Guid value) => new(value);
+
+ class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter
+ {
+ public override bool CanConvert(System.Type objectType)
+ {
+ return objectType == typeof(MyTestId);
+ }
+
+ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var id = (MyTestId)value;
+ serializer.Serialize(writer, id.Value);
+ }
+
+ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var guid = serializer.Deserialize(reader);
+ return guid.HasValue ? new MyTestId(guid.Value) : null;
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(System.Guid.Parse(reader.GetString()));
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Guid_implementations=20.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Guid_implementations=20.verified.txt
new file mode 100644
index 000000000..325a11006
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Guid_implementations=20.verified.txt
@@ -0,0 +1,77 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))]
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ readonly partial struct MyTestId : System.IComparable
+ {
+ public System.Guid Value { get; }
+
+ public MyTestId(System.Guid value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(System.Guid.NewGuid());
+ public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static implicit operator System.Guid(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(System.Guid value) => new(value);
+
+ class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter
+ {
+ public override bool CanConvert(System.Type objectType)
+ {
+ return objectType == typeof(MyTestId);
+ }
+
+ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var id = (MyTestId)value;
+ serializer.Serialize(writer, id.Value);
+ }
+
+ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var guid = serializer.Deserialize(reader);
+ return guid.HasValue ? new MyTestId(guid.Value) : null;
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(System.Guid.Parse(reader.GetString()));
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Guid_implementations=22.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Guid_implementations=22.verified.txt
new file mode 100644
index 000000000..0b16c7641
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Guid_implementations=22.verified.txt
@@ -0,0 +1,77 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))]
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ readonly partial struct MyTestId : System.IComparable, System.IEquatable
+ {
+ public System.Guid Value { get; }
+
+ public MyTestId(System.Guid value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(System.Guid.NewGuid());
+ public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static implicit operator System.Guid(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(System.Guid value) => new(value);
+
+ class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter
+ {
+ public override bool CanConvert(System.Type objectType)
+ {
+ return objectType == typeof(MyTestId);
+ }
+
+ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var id = (MyTestId)value;
+ serializer.Serialize(writer, id.Value);
+ }
+
+ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var guid = serializer.Deserialize(reader);
+ return guid.HasValue ? new MyTestId(guid.Value) : null;
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(System.Guid.Parse(reader.GetString()));
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Guid_implementations=8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Guid_implementations=8.verified.txt
new file mode 100644
index 000000000..b45f29a53
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Guid_implementations=8.verified.txt
@@ -0,0 +1,76 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))]
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ readonly partial struct MyTestId
+ {
+ public System.Guid Value { get; }
+
+ public MyTestId(System.Guid value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(System.Guid.NewGuid());
+ public static readonly MyTestId Empty = new MyTestId(System.Guid.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static explicit operator System.Guid(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(System.Guid value) => new(value);
+
+ class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter
+ {
+ public override bool CanConvert(System.Type objectType)
+ {
+ return objectType == typeof(MyTestId);
+ }
+
+ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var id = (MyTestId)value;
+ serializer.Serialize(writer, id.Value);
+ }
+
+ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var guid = serializer.Deserialize(reader);
+ return guid.HasValue ? new MyTestId(guid.Value) : null;
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(System.Guid.Parse(reader.GetString()));
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Int_implementations=10.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Int_implementations=10.verified.txt
new file mode 100644
index 000000000..446448988
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Int_implementations=10.verified.txt
@@ -0,0 +1,75 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))]
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ readonly partial struct MyTestId : System.IEquatable
+ {
+ public int Value { get; }
+
+ public MyTestId(int value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static explicit operator int(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(int value) => new(value);
+
+ class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter
+ {
+ public override bool CanConvert(System.Type objectType)
+ {
+ return objectType == typeof(MyTestId);
+ }
+
+ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var id = (MyTestId)value;
+ serializer.Serialize(writer, id.Value);
+ }
+
+ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var result = serializer.Deserialize(reader);
+ return result.HasValue ? new MyTestId(result.Value) : null;
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetInt32());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteNumberValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Int_implementations=12.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Int_implementations=12.verified.txt
new file mode 100644
index 000000000..a5af86762
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Int_implementations=12.verified.txt
@@ -0,0 +1,76 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))]
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ readonly partial struct MyTestId : System.IComparable
+ {
+ public int Value { get; }
+
+ public MyTestId(int value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static explicit operator int(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(int value) => new(value);
+
+ class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter
+ {
+ public override bool CanConvert(System.Type objectType)
+ {
+ return objectType == typeof(MyTestId);
+ }
+
+ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var id = (MyTestId)value;
+ serializer.Serialize(writer, id.Value);
+ }
+
+ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var result = serializer.Deserialize(reader);
+ return result.HasValue ? new MyTestId(result.Value) : null;
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetInt32());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteNumberValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Int_implementations=14.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Int_implementations=14.verified.txt
new file mode 100644
index 000000000..e7ea9adc9
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Int_implementations=14.verified.txt
@@ -0,0 +1,76 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))]
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ readonly partial struct MyTestId : System.IComparable, System.IEquatable
+ {
+ public int Value { get; }
+
+ public MyTestId(int value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static explicit operator int(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(int value) => new(value);
+
+ class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter
+ {
+ public override bool CanConvert(System.Type objectType)
+ {
+ return objectType == typeof(MyTestId);
+ }
+
+ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var id = (MyTestId)value;
+ serializer.Serialize(writer, id.Value);
+ }
+
+ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var result = serializer.Deserialize(reader);
+ return result.HasValue ? new MyTestId(result.Value) : null;
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetInt32());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteNumberValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Int_implementations=16.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Int_implementations=16.verified.txt
new file mode 100644
index 000000000..2e95edcf1
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Int_implementations=16.verified.txt
@@ -0,0 +1,75 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))]
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ readonly partial struct MyTestId
+ {
+ public int Value { get; }
+
+ public MyTestId(int value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static implicit operator int(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(int value) => new(value);
+
+ class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter
+ {
+ public override bool CanConvert(System.Type objectType)
+ {
+ return objectType == typeof(MyTestId);
+ }
+
+ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var id = (MyTestId)value;
+ serializer.Serialize(writer, id.Value);
+ }
+
+ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var result = serializer.Deserialize(reader);
+ return result.HasValue ? new MyTestId(result.Value) : null;
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetInt32());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteNumberValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Int_implementations=18.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Int_implementations=18.verified.txt
new file mode 100644
index 000000000..d4ef8925b
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Int_implementations=18.verified.txt
@@ -0,0 +1,75 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))]
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ readonly partial struct MyTestId : System.IEquatable
+ {
+ public int Value { get; }
+
+ public MyTestId(int value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static implicit operator int(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(int value) => new(value);
+
+ class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter
+ {
+ public override bool CanConvert(System.Type objectType)
+ {
+ return objectType == typeof(MyTestId);
+ }
+
+ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var id = (MyTestId)value;
+ serializer.Serialize(writer, id.Value);
+ }
+
+ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var result = serializer.Deserialize(reader);
+ return result.HasValue ? new MyTestId(result.Value) : null;
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetInt32());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteNumberValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Int_implementations=20.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Int_implementations=20.verified.txt
new file mode 100644
index 000000000..24cd3dc51
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Int_implementations=20.verified.txt
@@ -0,0 +1,76 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))]
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ readonly partial struct MyTestId : System.IComparable
+ {
+ public int Value { get; }
+
+ public MyTestId(int value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static implicit operator int(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(int value) => new(value);
+
+ class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter
+ {
+ public override bool CanConvert(System.Type objectType)
+ {
+ return objectType == typeof(MyTestId);
+ }
+
+ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var id = (MyTestId)value;
+ serializer.Serialize(writer, id.Value);
+ }
+
+ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var result = serializer.Deserialize(reader);
+ return result.HasValue ? new MyTestId(result.Value) : null;
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetInt32());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteNumberValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Int_implementations=22.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Int_implementations=22.verified.txt
new file mode 100644
index 000000000..032f45167
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Int_implementations=22.verified.txt
@@ -0,0 +1,76 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))]
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ readonly partial struct MyTestId : System.IComparable, System.IEquatable
+ {
+ public int Value { get; }
+
+ public MyTestId(int value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static implicit operator int(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(int value) => new(value);
+
+ class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter
+ {
+ public override bool CanConvert(System.Type objectType)
+ {
+ return objectType == typeof(MyTestId);
+ }
+
+ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var id = (MyTestId)value;
+ serializer.Serialize(writer, id.Value);
+ }
+
+ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var result = serializer.Deserialize(reader);
+ return result.HasValue ? new MyTestId(result.Value) : null;
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetInt32());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteNumberValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Int_implementations=8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Int_implementations=8.verified.txt
new file mode 100644
index 000000000..7107f0c9a
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Int_implementations=8.verified.txt
@@ -0,0 +1,75 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))]
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ readonly partial struct MyTestId
+ {
+ public int Value { get; }
+
+ public MyTestId(int value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static explicit operator int(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(int value) => new(value);
+
+ class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter
+ {
+ public override bool CanConvert(System.Type objectType)
+ {
+ return objectType == typeof(MyTestId);
+ }
+
+ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var id = (MyTestId)value;
+ serializer.Serialize(writer, id.Value);
+ }
+
+ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var result = serializer.Deserialize(reader);
+ return result.HasValue ? new MyTestId(result.Value) : null;
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetInt32());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteNumberValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Long_implementations=10.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Long_implementations=10.verified.txt
new file mode 100644
index 000000000..d39b0a6db
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Long_implementations=10.verified.txt
@@ -0,0 +1,75 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))]
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ readonly partial struct MyTestId : System.IEquatable
+ {
+ public long Value { get; }
+
+ public MyTestId(long value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static explicit operator long(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(long value) => new(value);
+
+ class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter
+ {
+ public override bool CanConvert(System.Type objectType)
+ {
+ return objectType == typeof(MyTestId);
+ }
+
+ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var id = (MyTestId)value;
+ serializer.Serialize(writer, id.Value);
+ }
+
+ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var result = serializer.Deserialize(reader);
+ return result.HasValue ? new MyTestId(result.Value) : null;
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetInt64());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteNumberValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Long_implementations=12.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Long_implementations=12.verified.txt
new file mode 100644
index 000000000..4176bca1a
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Long_implementations=12.verified.txt
@@ -0,0 +1,76 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))]
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ readonly partial struct MyTestId : System.IComparable
+ {
+ public long Value { get; }
+
+ public MyTestId(long value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static explicit operator long(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(long value) => new(value);
+
+ class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter
+ {
+ public override bool CanConvert(System.Type objectType)
+ {
+ return objectType == typeof(MyTestId);
+ }
+
+ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var id = (MyTestId)value;
+ serializer.Serialize(writer, id.Value);
+ }
+
+ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var result = serializer.Deserialize(reader);
+ return result.HasValue ? new MyTestId(result.Value) : null;
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetInt64());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteNumberValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Long_implementations=14.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Long_implementations=14.verified.txt
new file mode 100644
index 000000000..04d582995
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Long_implementations=14.verified.txt
@@ -0,0 +1,76 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))]
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ readonly partial struct MyTestId : System.IComparable, System.IEquatable
+ {
+ public long Value { get; }
+
+ public MyTestId(long value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static explicit operator long(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(long value) => new(value);
+
+ class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter
+ {
+ public override bool CanConvert(System.Type objectType)
+ {
+ return objectType == typeof(MyTestId);
+ }
+
+ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var id = (MyTestId)value;
+ serializer.Serialize(writer, id.Value);
+ }
+
+ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var result = serializer.Deserialize(reader);
+ return result.HasValue ? new MyTestId(result.Value) : null;
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetInt64());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteNumberValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Long_implementations=16.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Long_implementations=16.verified.txt
new file mode 100644
index 000000000..af207d187
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Long_implementations=16.verified.txt
@@ -0,0 +1,75 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))]
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ readonly partial struct MyTestId
+ {
+ public long Value { get; }
+
+ public MyTestId(long value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static implicit operator long(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(long value) => new(value);
+
+ class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter
+ {
+ public override bool CanConvert(System.Type objectType)
+ {
+ return objectType == typeof(MyTestId);
+ }
+
+ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var id = (MyTestId)value;
+ serializer.Serialize(writer, id.Value);
+ }
+
+ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var result = serializer.Deserialize(reader);
+ return result.HasValue ? new MyTestId(result.Value) : null;
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetInt64());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteNumberValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Long_implementations=18.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Long_implementations=18.verified.txt
new file mode 100644
index 000000000..bb05da21c
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Long_implementations=18.verified.txt
@@ -0,0 +1,75 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))]
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ readonly partial struct MyTestId : System.IEquatable
+ {
+ public long Value { get; }
+
+ public MyTestId(long value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static implicit operator long(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(long value) => new(value);
+
+ class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter
+ {
+ public override bool CanConvert(System.Type objectType)
+ {
+ return objectType == typeof(MyTestId);
+ }
+
+ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var id = (MyTestId)value;
+ serializer.Serialize(writer, id.Value);
+ }
+
+ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var result = serializer.Deserialize(reader);
+ return result.HasValue ? new MyTestId(result.Value) : null;
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetInt64());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteNumberValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Long_implementations=20.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Long_implementations=20.verified.txt
new file mode 100644
index 000000000..a3986b3d8
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Long_implementations=20.verified.txt
@@ -0,0 +1,76 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))]
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ readonly partial struct MyTestId : System.IComparable
+ {
+ public long Value { get; }
+
+ public MyTestId(long value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static implicit operator long(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(long value) => new(value);
+
+ class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter
+ {
+ public override bool CanConvert(System.Type objectType)
+ {
+ return objectType == typeof(MyTestId);
+ }
+
+ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var id = (MyTestId)value;
+ serializer.Serialize(writer, id.Value);
+ }
+
+ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var result = serializer.Deserialize(reader);
+ return result.HasValue ? new MyTestId(result.Value) : null;
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetInt64());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteNumberValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Long_implementations=22.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Long_implementations=22.verified.txt
new file mode 100644
index 000000000..7cf5b7899
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Long_implementations=22.verified.txt
@@ -0,0 +1,76 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))]
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ readonly partial struct MyTestId : System.IComparable, System.IEquatable
+ {
+ public long Value { get; }
+
+ public MyTestId(long value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static implicit operator long(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(long value) => new(value);
+
+ class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter
+ {
+ public override bool CanConvert(System.Type objectType)
+ {
+ return objectType == typeof(MyTestId);
+ }
+
+ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var id = (MyTestId)value;
+ serializer.Serialize(writer, id.Value);
+ }
+
+ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var result = serializer.Deserialize(reader);
+ return result.HasValue ? new MyTestId(result.Value) : null;
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetInt64());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteNumberValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Long_implementations=8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Long_implementations=8.verified.txt
new file mode 100644
index 000000000..9e49ef94b
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=Long_implementations=8.verified.txt
@@ -0,0 +1,75 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))]
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ readonly partial struct MyTestId
+ {
+ public long Value { get; }
+
+ public MyTestId(long value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(0);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static explicit operator long(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(long value) => new(value);
+
+ class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter
+ {
+ public override bool CanConvert(System.Type objectType)
+ {
+ return objectType == typeof(MyTestId);
+ }
+
+ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var id = (MyTestId)value;
+ serializer.Serialize(writer, id.Value);
+ }
+
+ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var result = serializer.Deserialize(reader);
+ return result.HasValue ? new MyTestId(result.Value) : null;
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetInt64());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteNumberValue(value.Value);
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=MassTransitNewId_implementations=10.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=MassTransitNewId_implementations=10.verified.txt
new file mode 100644
index 000000000..5df7aa147
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=MassTransitNewId_implementations=10.verified.txt
@@ -0,0 +1,76 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))]
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ readonly partial struct MyTestId : System.IEquatable
+ {
+ public MassTransit.NewId Value { get; }
+
+ public MyTestId(MassTransit.NewId value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(MassTransit.NewId.Next());
+ public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static explicit operator MassTransit.NewId(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(MassTransit.NewId value) => new(value);
+
+ class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter
+ {
+ public override bool CanConvert(System.Type objectType)
+ {
+ return objectType == typeof(MyTestId);
+ }
+
+ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var id = (MyTestId)value;
+ serializer.Serialize(writer, id.Value.ToGuid());
+ }
+
+ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var guid = serializer.Deserialize(reader);
+ return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null;
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid()));
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value.ToGuid());
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=MassTransitNewId_implementations=12.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=MassTransitNewId_implementations=12.verified.txt
new file mode 100644
index 000000000..083a58a72
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=MassTransitNewId_implementations=12.verified.txt
@@ -0,0 +1,77 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))]
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ readonly partial struct MyTestId : System.IComparable
+ {
+ public MassTransit.NewId Value { get; }
+
+ public MyTestId(MassTransit.NewId value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(MassTransit.NewId.Next());
+ public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static explicit operator MassTransit.NewId(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(MassTransit.NewId value) => new(value);
+
+ class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter
+ {
+ public override bool CanConvert(System.Type objectType)
+ {
+ return objectType == typeof(MyTestId);
+ }
+
+ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var id = (MyTestId)value;
+ serializer.Serialize(writer, id.Value.ToGuid());
+ }
+
+ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var guid = serializer.Deserialize(reader);
+ return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null;
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid()));
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value.ToGuid());
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=MassTransitNewId_implementations=14.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=MassTransitNewId_implementations=14.verified.txt
new file mode 100644
index 000000000..33586cbb1
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=MassTransitNewId_implementations=14.verified.txt
@@ -0,0 +1,77 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))]
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ readonly partial struct MyTestId : System.IComparable, System.IEquatable
+ {
+ public MassTransit.NewId Value { get; }
+
+ public MyTestId(MassTransit.NewId value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(MassTransit.NewId.Next());
+ public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static explicit operator MassTransit.NewId(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(MassTransit.NewId value) => new(value);
+
+ class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter
+ {
+ public override bool CanConvert(System.Type objectType)
+ {
+ return objectType == typeof(MyTestId);
+ }
+
+ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var id = (MyTestId)value;
+ serializer.Serialize(writer, id.Value.ToGuid());
+ }
+
+ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var guid = serializer.Deserialize(reader);
+ return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null;
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid()));
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value.ToGuid());
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=MassTransitNewId_implementations=16.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=MassTransitNewId_implementations=16.verified.txt
new file mode 100644
index 000000000..4f7c36e7a
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=MassTransitNewId_implementations=16.verified.txt
@@ -0,0 +1,76 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))]
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ readonly partial struct MyTestId
+ {
+ public MassTransit.NewId Value { get; }
+
+ public MyTestId(MassTransit.NewId value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(MassTransit.NewId.Next());
+ public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static implicit operator MassTransit.NewId(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(MassTransit.NewId value) => new(value);
+
+ class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter
+ {
+ public override bool CanConvert(System.Type objectType)
+ {
+ return objectType == typeof(MyTestId);
+ }
+
+ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var id = (MyTestId)value;
+ serializer.Serialize(writer, id.Value.ToGuid());
+ }
+
+ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var guid = serializer.Deserialize(reader);
+ return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null;
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid()));
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value.ToGuid());
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=MassTransitNewId_implementations=18.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=MassTransitNewId_implementations=18.verified.txt
new file mode 100644
index 000000000..933c5241b
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=MassTransitNewId_implementations=18.verified.txt
@@ -0,0 +1,76 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))]
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ readonly partial struct MyTestId : System.IEquatable
+ {
+ public MassTransit.NewId Value { get; }
+
+ public MyTestId(MassTransit.NewId value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(MassTransit.NewId.Next());
+ public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static implicit operator MassTransit.NewId(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(MassTransit.NewId value) => new(value);
+
+ class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter
+ {
+ public override bool CanConvert(System.Type objectType)
+ {
+ return objectType == typeof(MyTestId);
+ }
+
+ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var id = (MyTestId)value;
+ serializer.Serialize(writer, id.Value.ToGuid());
+ }
+
+ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var guid = serializer.Deserialize(reader);
+ return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null;
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid()));
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value.ToGuid());
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=MassTransitNewId_implementations=20.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=MassTransitNewId_implementations=20.verified.txt
new file mode 100644
index 000000000..7c39f970f
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=MassTransitNewId_implementations=20.verified.txt
@@ -0,0 +1,77 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))]
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ readonly partial struct MyTestId : System.IComparable
+ {
+ public MassTransit.NewId Value { get; }
+
+ public MyTestId(MassTransit.NewId value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(MassTransit.NewId.Next());
+ public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static implicit operator MassTransit.NewId(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(MassTransit.NewId value) => new(value);
+
+ class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter
+ {
+ public override bool CanConvert(System.Type objectType)
+ {
+ return objectType == typeof(MyTestId);
+ }
+
+ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var id = (MyTestId)value;
+ serializer.Serialize(writer, id.Value.ToGuid());
+ }
+
+ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var guid = serializer.Deserialize(reader);
+ return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null;
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid()));
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value.ToGuid());
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=MassTransitNewId_implementations=22.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=MassTransitNewId_implementations=22.verified.txt
new file mode 100644
index 000000000..c18e9ed4b
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=MassTransitNewId_implementations=22.verified.txt
@@ -0,0 +1,77 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))]
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ readonly partial struct MyTestId : System.IComparable, System.IEquatable
+ {
+ public MassTransit.NewId Value { get; }
+
+ public MyTestId(MassTransit.NewId value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(MassTransit.NewId.Next());
+ public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
+ public static implicit operator MassTransit.NewId(MyTestId id) => id.Value;
+ public static implicit operator MyTestId(MassTransit.NewId value) => new(value);
+
+ class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter
+ {
+ public override bool CanConvert(System.Type objectType)
+ {
+ return objectType == typeof(MyTestId);
+ }
+
+ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var id = (MyTestId)value;
+ serializer.Serialize(writer, id.Value.ToGuid());
+ }
+
+ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var guid = serializer.Deserialize(reader);
+ return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null;
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid()));
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value.ToGuid());
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=MassTransitNewId_implementations=8.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=MassTransitNewId_implementations=8.verified.txt
new file mode 100644
index 000000000..2afe738c7
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=MassTransitNewId_implementations=8.verified.txt
@@ -0,0 +1,76 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+namespace Some.Namespace
+{
+ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))]
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ readonly partial struct MyTestId
+ {
+ public MassTransit.NewId Value { get; }
+
+ public MyTestId(MassTransit.NewId value)
+ {
+ Value = value;
+ }
+
+ public static MyTestId New() => new MyTestId(MassTransit.NewId.Next());
+ public static readonly MyTestId Empty = new MyTestId(MassTransit.NewId.Empty);
+
+ public bool Equals(MyTestId other) => this.Value.Equals(other.Value);
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static explicit operator MassTransit.NewId(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(MassTransit.NewId value) => new(value);
+
+ class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter
+ {
+ public override bool CanConvert(System.Type objectType)
+ {
+ return objectType == typeof(MyTestId);
+ }
+
+ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var id = (MyTestId)value;
+ serializer.Serialize(writer, id.Value.ToGuid());
+ }
+
+ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ var guid = serializer.Deserialize(reader);
+ return guid.HasValue ? new MyTestId(MassTransit.NewId.FromGuid(guid.Value)) : null;
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(MassTransit.NewId.FromGuid(reader.GetGuid()));
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.Value.ToGuid());
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=NullableString_implementations=10.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=NullableString_implementations=10.verified.txt
new file mode 100644
index 000000000..871100a9b
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=NullableString_implementations=10.verified.txt
@@ -0,0 +1,97 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by the StronglyTypedId source generator
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+#pragma warning disable 1591 // publicly visible type or member must be documented
+
+#nullable enable
+namespace Some.Namespace
+{
+ [Newtonsoft.Json.JsonConverter(typeof(MyTestIdNewtonsoftJsonConverter))]
+ [System.Text.Json.Serialization.JsonConverter(typeof(MyTestIdSystemTextJsonConverter))]
+ readonly partial struct MyTestId : System.IEquatable
+ {
+ public string? Value { get; }
+
+ public MyTestId(string? value)
+ {
+ Value = value;
+ }
+
+ public static readonly MyTestId Empty = new MyTestId(string.Empty);
+
+ public bool Equals(MyTestId other)
+ {
+ return (Value, other.Value) switch
+ {
+ (null, null) => true,
+ (null, _) => false,
+ (_, null) => false,
+ (_, _) => Value.Equals(other.Value),
+ };
+ }
+ public override bool Equals(object? obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ return obj is MyTestId other && Equals(other);
+ }
+
+ public override int GetHashCode() => Value?.GetHashCode() ?? 0;
+ public override string? ToString() => Value;
+ public static bool operator ==(MyTestId a, MyTestId b) => a.Equals(b);
+ public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
+ public static explicit operator string?(MyTestId id) => id.Value;
+ public static explicit operator MyTestId(string? value) => new(value);
+
+ class MyTestIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter
+ {
+ public override bool CanConvert(System.Type objectType)
+ {
+ return objectType == typeof(MyTestId);
+ }
+
+ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? value, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ if (value is null)
+ {
+ serializer.Serialize(writer, null);
+ }
+ else
+ {
+ var id = (MyTestId)value;
+ serializer.Serialize(writer, id.Value);
+ }
+ }
+
+ public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object? existingValue, Newtonsoft.Json.JsonSerializer serializer)
+ {
+ return new MyTestId(serializer.Deserialize(reader));
+ }
+ }
+
+ class MyTestIdSystemTextJsonConverter : System.Text.Json.Serialization.JsonConverter
+ {
+ public override MyTestId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
+ {
+ return new MyTestId(reader.GetString());
+ }
+
+ public override void Write(System.Text.Json.Utf8JsonWriter writer, MyTestId value, System.Text.Json.JsonSerializerOptions options)
+ {
+ if (value.Value is null)
+ {
+ writer.WriteNullValue();
+ }
+ else
+ {
+ writer.WriteStringValue(value.Value);
+ }
+ }
+ }
+ }
+}
diff --git a/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=NullableString_implementations=12.verified.txt b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=NullableString_implementations=12.verified.txt
new file mode 100644
index 000000000..e659d2ca8
--- /dev/null
+++ b/test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesIdCorrectly_ns=Some.Namespace_converter=12_backingType=NullableString_implementations=12.verified.txt
@@ -0,0 +1,107 @@
+//------------------------------------------------------------------------------
+//