Skip to content

Commit 74d9576

Browse files
authored
IComparable non generic (#17)
1 parent f4e093d commit 74d9576

File tree

128 files changed

+1830
-132
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+1830
-132
lines changed

src/StronglyTypedIds/SourceGenerationHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ private static void ReplaceInterfaces(StringBuilder sb, bool useIEquatable, bool
233233
if (useIComparable)
234234
{
235235
interfaces.Add("System.IComparable<TESTID>");
236+
interfaces.Add("System.IComparable");
236237
}
237238

238239
if (useIEquatable)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11

22
#pragma warning disable CA1036
3+
#nullable enable
34
public int CompareTo(TESTID other) => Value.CompareTo(other.Value);
5+
6+
public int CompareTo(object? obj)
7+
{
8+
if (ReferenceEquals(obj, null))
9+
return 1;
10+
11+
if (obj is not TESTID other)
12+
throw new System.ArgumentException("Object is not a TESTID");
13+
14+
return Value.CompareTo(other.Value);
15+
}
16+
#nullable disable
417
#pragma warning restore CA1036
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11

22
#pragma warning disable CA1036
3+
#nullable enable
34
public int CompareTo(TESTID other) => Value.CompareTo(other.Value);
5+
6+
public int CompareTo(object? obj)
7+
{
8+
if (ReferenceEquals(obj, null))
9+
return 1;
10+
11+
if (obj is not TESTID other)
12+
throw new System.ArgumentException("Object is not a TESTID");
13+
14+
return Value.CompareTo(other.Value);
15+
}
16+
#nullable disable
417
#pragma warning restore CA1036
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11

22
#pragma warning disable CA1036
3+
#nullable enable
34
public int CompareTo(TESTID other) => Value.CompareTo(other.Value);
4-
#pragma warning restore CA1036
5+
6+
public int CompareTo(object? obj)
7+
{
8+
if (ReferenceEquals(obj, null))
9+
return 1;
10+
11+
if (obj is not TESTID other)
12+
throw new System.ArgumentException("Object is not a TESTID");
13+
14+
return Value.CompareTo(other.Value);
15+
}
16+
#nullable disable
17+
#pragma warning restore CA1036
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
11
 #pragma warning disable CA1036
2+
#nullable enable
23
public int CompareTo(TESTID other) => Value.CompareTo(other.Value);
4+
5+
public int CompareTo(object? obj)
6+
{
7+
if (ReferenceEquals(obj, null))
8+
return 1;
9+
10+
if (obj is not TESTID other)
11+
throw new System.ArgumentException("Object is not a TESTID");
12+
13+
return Value.CompareTo(other.Value);
14+
}
15+
#nullable disable
316
#pragma warning restore CA1036

src/StronglyTypedIds/Templates/NullableString/NullableString_IComparable.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#pragma warning disable CA1036
2+
#nullable enable
23
public int CompareTo(TESTID other)
34
{
45
return (Value, other.Value) switch
@@ -9,4 +10,15 @@ public int CompareTo(TESTID other)
910
(_, _) => Value.CompareTo(other.Value),
1011
};
1112
}
13+
public int CompareTo(object? obj)
14+
{
15+
if (ReferenceEquals(obj, null))
16+
return 1;
17+
18+
if (obj is not TESTID other)
19+
throw new System.ArgumentException("Object is not a TESTID");
20+
21+
return Value.CompareTo(other.Value);
22+
}
23+
#nullable disable
1224
#pragma warning restore CA1036

src/StronglyTypedIds/Templates/String/String_IComparable.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#pragma warning disable CA1036
2+
#nullable enable
23
public int CompareTo(TESTID other)
34
{
45
return (Value, other.Value) switch
@@ -9,4 +10,16 @@ public int CompareTo(TESTID other)
910
(_, _) => Value.CompareTo(other.Value),
1011
};
1112
}
13+
14+
public int CompareTo(object? obj)
15+
{
16+
if (ReferenceEquals(obj, null))
17+
return 1;
18+
19+
if (obj is not TESTID other)
20+
throw new System.ArgumentException("Object is not a TESTID");
21+
22+
return Value.CompareTo(other.Value);
23+
}
24+
#nullable disable
1225
#pragma warning restore CA1036

test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.Core3_1.verified.txt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
[System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
1515
[Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))]
1616
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1036:Override methods on comparable types")]
17-
readonly partial struct MyTestId : System.IComparable<MyTestId>, System.IEquatable<MyTestId>, System.IParsable<MyTestId>, System.IConvertible, IStronglyTypedId<System.Guid>
17+
readonly partial struct MyTestId : System.IComparable<MyTestId>, System.IComparable, System.IEquatable<MyTestId>, System.IParsable<MyTestId>, System.IConvertible, IStronglyTypedId<System.Guid>
1818
{
1919
public System.Guid Value { get; }
2020

@@ -39,7 +39,20 @@
3939
public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
4040

4141
#pragma warning disable CA1036
42+
#nullable enable
4243
public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
44+
45+
public int CompareTo(object? obj)
46+
{
47+
if (ReferenceEquals(obj, null))
48+
return 1;
49+
50+
if (obj is not MyTestId other)
51+
throw new System.ArgumentException("Object is not a MyTestId");
52+
53+
return Value.CompareTo(other.Value);
54+
}
55+
#nullable disable
4356
#pragma warning restore CA1036
4457

4558

test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet6_0.verified.txt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
[System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
1515
[Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))]
1616
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1036:Override methods on comparable types")]
17-
readonly partial struct MyTestId : System.IComparable<MyTestId>, System.IEquatable<MyTestId>, System.IParsable<MyTestId>, System.IConvertible, IStronglyTypedId<System.Guid>
17+
readonly partial struct MyTestId : System.IComparable<MyTestId>, System.IComparable, System.IEquatable<MyTestId>, System.IParsable<MyTestId>, System.IConvertible, IStronglyTypedId<System.Guid>
1818
{
1919
public System.Guid Value { get; }
2020

@@ -39,7 +39,20 @@
3939
public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
4040

4141
#pragma warning disable CA1036
42+
#nullable enable
4243
public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
44+
45+
public int CompareTo(object? obj)
46+
{
47+
if (ReferenceEquals(obj, null))
48+
return 1;
49+
50+
if (obj is not MyTestId other)
51+
throw new System.ArgumentException("Object is not a MyTestId");
52+
53+
return Value.CompareTo(other.Value);
54+
}
55+
#nullable disable
4356
#pragma warning restore CA1036
4457

4558

test/StronglyTypedIds.Tests/Snapshots/SourceGenerationHelperSnapshotTests.GeneratesFullIdCorrectly_type=Guid.DotNet7_0.verified.txt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
[System.ComponentModel.TypeConverter(typeof(MyTestIdTypeConverter))]
1515
[Swashbuckle.AspNetCore.Annotations.SwaggerSchemaFilter(typeof(MyTestIdSchemaFilter))]
1616
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1036:Override methods on comparable types")]
17-
readonly partial struct MyTestId : System.IComparable<MyTestId>, System.IEquatable<MyTestId>, System.IParsable<MyTestId>, System.IConvertible, IStronglyTypedId<System.Guid>
17+
readonly partial struct MyTestId : System.IComparable<MyTestId>, System.IComparable, System.IEquatable<MyTestId>, System.IParsable<MyTestId>, System.IConvertible, IStronglyTypedId<System.Guid>
1818
{
1919
public System.Guid Value { get; }
2020

@@ -39,7 +39,20 @@
3939
public static bool operator !=(MyTestId a, MyTestId b) => !(a == b);
4040

4141
#pragma warning disable CA1036
42+
#nullable enable
4243
public int CompareTo(MyTestId other) => Value.CompareTo(other.Value);
44+
45+
public int CompareTo(object? obj)
46+
{
47+
if (ReferenceEquals(obj, null))
48+
return 1;
49+
50+
if (obj is not MyTestId other)
51+
throw new System.ArgumentException("Object is not a MyTestId");
52+
53+
return Value.CompareTo(other.Value);
54+
}
55+
#nullable disable
4356
#pragma warning restore CA1036
4457

4558

0 commit comments

Comments
 (0)