Skip to content

Commit fd8389d

Browse files
committed
Updated string comparison and class methods.
1 parent dc0a633 commit fd8389d

12 files changed

+216
-100
lines changed

Diff for: src/LightResults.Extensions.GeneratedIdentifier/GeneratedIdentifierSourceGenerator.cs

+171-71
Large diffs are not rendered by default.

Diff for: src/LightResults.Extensions.GeneratedIdentifier/LightResults.Extensions.GeneratedIdentifier.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<!-- Output -->
3737
<PropertyGroup>
3838
<AssemblyName>LightResults.Extensions.GeneratedIdentifier</AssemblyName>
39-
<Version>9.0.0-preview.7</Version>
39+
<Version>9.0.0-preview.8</Version>
4040
<AssemblyVersion>9.0.0.0</AssemblyVersion>
4141
<FileVersion>9.0.0.0</FileVersion>
4242
<NeutralLanguage>en-US</NeutralLanguage>

Diff for: tests/LightResults.Extensions.GeneratedIdentifier.Tests/GeneratedIdentifierSourceGeneratorTests.GenerateGuidIdentifier_WithNamespace.verified.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ readonly partial struct TestGuidId :
9797
/// <inheritdoc />
9898
public bool Equals(TestGuidId other)
9999
{
100-
return _value == other._value;
100+
return _value.Equals(other._value);
101101
}
102102

103103
/// <inheritdoc />

Diff for: tests/LightResults.Extensions.GeneratedIdentifier.Tests/GeneratedIdentifierSourceGeneratorTests.GenerateGuidIdentifier_WithoutNamespace.verified.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ readonly partial struct TestGuidId :
9595
/// <inheritdoc />
9696
public bool Equals(TestGuidId other)
9797
{
98-
return _value == other._value;
98+
return _value.Equals(other._value);
9999
}
100100

101101
/// <inheritdoc />

Diff for: tests/LightResults.Extensions.GeneratedIdentifier.Tests/GeneratedIdentifierSourceGeneratorTests.GenerateIntIdentifier_WithNamespace.verified.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ readonly partial struct TestIntId :
9797
/// <inheritdoc />
9898
public bool Equals(TestIntId other)
9999
{
100-
return _value == other._value;
100+
return _value.Equals(other._value);
101101
}
102102

103103
/// <inheritdoc />

Diff for: tests/LightResults.Extensions.GeneratedIdentifier.Tests/GeneratedIdentifierSourceGeneratorTests.GenerateIntIdentifier_WithoutNamespace.verified.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ readonly partial struct TestIntId :
9595
/// <inheritdoc />
9696
public bool Equals(TestIntId other)
9797
{
98-
return _value == other._value;
98+
return _value.Equals(other._value);
9999
}
100100

101101
/// <inheritdoc />

Diff for: tests/LightResults.Extensions.GeneratedIdentifier.Tests/GeneratedIdentifierSourceGeneratorTests.GenerateLongIdentifier_WithNamespace.verified.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ readonly partial struct TestLongId :
9797
/// <inheritdoc />
9898
public bool Equals(TestLongId other)
9999
{
100-
return _value == other._value;
100+
return _value.Equals(other._value);
101101
}
102102

103103
/// <inheritdoc />

Diff for: tests/LightResults.Extensions.GeneratedIdentifier.Tests/GeneratedIdentifierSourceGeneratorTests.GenerateLongIdentifier_WithoutNamespace.verified.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ readonly partial struct TestLongId :
9595
/// <inheritdoc />
9696
public bool Equals(TestLongId other)
9797
{
98-
return _value == other._value;
98+
return _value.Equals(other._value);
9999
}
100100

101101
/// <inheritdoc />

Diff for: tests/LightResults.Extensions.GeneratedIdentifier.Tests/GeneratedIdentifierSourceGeneratorTests.GenerateShortIdentifier_WithNamespace.verified.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ readonly partial struct TestShortId :
9797
/// <inheritdoc />
9898
public bool Equals(TestShortId other)
9999
{
100-
return _value == other._value;
100+
return _value.Equals(other._value);
101101
}
102102

103103
/// <inheritdoc />

Diff for: tests/LightResults.Extensions.GeneratedIdentifier.Tests/GeneratedIdentifierSourceGeneratorTests.GenerateShortIdentifier_WithoutNamespace.verified.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ readonly partial struct TestShortId :
9595
/// <inheritdoc />
9696
public bool Equals(TestShortId other)
9797
{
98-
return _value == other._value;
98+
return _value.Equals(other._value);
9999
}
100100

101101
/// <inheritdoc />

Diff for: tests/LightResults.Extensions.GeneratedIdentifier.Tests/GeneratedIdentifierSourceGeneratorTests.GenerateStringIdentifier_WithNamespace.verified.txt

+18-10
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ sealed partial class TestStringId :
6666
return false;
6767
if (ReferenceEquals(this, other))
6868
return true;
69-
return _value == other._value;
69+
return string.Equals(_value, other._value, StringComparison.Ordinal);
7070
}
7171

7272
/// <inheritdoc />
@@ -82,25 +82,25 @@ sealed partial class TestStringId :
8282
/// <inheritdoc />
8383
public override int GetHashCode()
8484
{
85-
return _value.GetHashCode();
85+
return StringComparer.Ordinal.GetHashCode(_value);
8686
}
8787

8888
/// <summary>Determines whether two instances of <see cref="TestStringId" /> are equal.</summary>
8989
/// <param name="left">The first instance to compare.</param>
9090
/// <param name="right">The second instance to compare.</param>
9191
/// <returns><c>true</c> if the instances are equal; otherwise, <c>false</c>.</returns>
92-
public static bool operator ==(TestStringId left, TestStringId right)
92+
public static bool operator ==(TestStringId? left, TestStringId? right)
9393
{
94-
return left.Equals(right);
94+
return left is not null && left.Equals(right);
9595
}
9696

9797
/// <summary>Determines whether two instances of <see cref="TestStringId" /> are not equal.</summary>
9898
/// <param name="left">The first instance to compare.</param>
9999
/// <param name="right">The second instance to compare.</param>
100100
/// <returns><c>true</c> if the instances are not equal; otherwise, <c>false</c>.</returns>
101-
public static bool operator !=(TestStringId left, TestStringId right)
101+
public static bool operator !=(TestStringId? left, TestStringId? right)
102102
{
103-
return !left.Equals(right);
103+
return left is null || !left.Equals(right);
104104
}
105105

106106
/// <inheritdoc />
@@ -127,35 +127,43 @@ sealed partial class TestStringId :
127127
/// <param name="left">The first instance to compare.</param>
128128
/// <param name="right">The second instance to compare.</param>
129129
/// <returns><c>true</c> if the first instance is less than the second instance; otherwise, <c>false</c>.</returns>
130-
public static bool operator <(TestStringId left, TestStringId right)
130+
public static bool operator <(TestStringId? left, TestStringId? right)
131131
{
132+
if (left is null)
133+
return (right is null ? 0 : -1) < 0;
132134
return left.CompareTo(right) < 0;
133135
}
134136

135137
/// <summary>Determines whether the first instance of <see cref="TestStringId" /> is greater than the second instance.</summary>
136138
/// <param name="left">The first instance to compare.</param>
137139
/// <param name="right">The second instance to compare.</param>
138140
/// <returns><c>true</c> if the first instance is greater than the second instance; otherwise, <c>false</c>.</returns>
139-
public static bool operator >(TestStringId left, TestStringId right)
141+
public static bool operator >(TestStringId? left, TestStringId? right)
140142
{
143+
if (left is null)
144+
return false;
141145
return left.CompareTo(right) > 0;
142146
}
143147

144148
/// <summary>Determines whether the first instance of <see cref="TestStringId" /> is less than or equal to the second instance.</summary>
145149
/// <param name="left">The first instance to compare.</param>
146150
/// <param name="right">The second instance to compare.</param>
147151
/// <returns><c>true</c> if the first instance is less than or equal to the second instance; otherwise, <c>false</c>.</returns>
148-
public static bool operator <=(TestStringId left, TestStringId right)
152+
public static bool operator <=(TestStringId? left, TestStringId? right)
149153
{
154+
if (left is null)
155+
return true;
150156
return left.CompareTo(right) <= 0;
151157
}
152158

153159
/// <summary>Determines whether the first instance of <see cref="TestStringId" /> is greater than or equal to the second instance.</summary>
154160
/// <param name="left">The first instance to compare.</param>
155161
/// <param name="right">The second instance to compare.</param>
156162
/// <returns><c>true</c> if the first instance is greater than or equal to the second instance; otherwise, <c>false</c>.</returns>
157-
public static bool operator >=(TestStringId left, TestStringId right)
163+
public static bool operator >=(TestStringId? left, TestStringId? right)
158164
{
165+
if (left is null)
166+
return (right is null ? 0 : -1) >= 0;
159167
return left.CompareTo(right) >= 0;
160168
}
161169

Diff for: tests/LightResults.Extensions.GeneratedIdentifier.Tests/GeneratedIdentifierSourceGeneratorTests.GenerateStringIdentifier_WithoutNamespace.verified.txt

+18-10
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ sealed partial class TestStringId :
6464
return false;
6565
if (ReferenceEquals(this, other))
6666
return true;
67-
return _value == other._value;
67+
return string.Equals(_value, other._value, StringComparison.Ordinal);
6868
}
6969

7070
/// <inheritdoc />
@@ -80,25 +80,25 @@ sealed partial class TestStringId :
8080
/// <inheritdoc />
8181
public override int GetHashCode()
8282
{
83-
return _value.GetHashCode();
83+
return StringComparer.Ordinal.GetHashCode(_value);
8484
}
8585

8686
/// <summary>Determines whether two instances of <see cref="TestStringId" /> are equal.</summary>
8787
/// <param name="left">The first instance to compare.</param>
8888
/// <param name="right">The second instance to compare.</param>
8989
/// <returns><c>true</c> if the instances are equal; otherwise, <c>false</c>.</returns>
90-
public static bool operator ==(TestStringId left, TestStringId right)
90+
public static bool operator ==(TestStringId? left, TestStringId? right)
9191
{
92-
return left.Equals(right);
92+
return left is not null && left.Equals(right);
9393
}
9494

9595
/// <summary>Determines whether two instances of <see cref="TestStringId" /> are not equal.</summary>
9696
/// <param name="left">The first instance to compare.</param>
9797
/// <param name="right">The second instance to compare.</param>
9898
/// <returns><c>true</c> if the instances are not equal; otherwise, <c>false</c>.</returns>
99-
public static bool operator !=(TestStringId left, TestStringId right)
99+
public static bool operator !=(TestStringId? left, TestStringId? right)
100100
{
101-
return !left.Equals(right);
101+
return left is null || !left.Equals(right);
102102
}
103103

104104
/// <inheritdoc />
@@ -125,35 +125,43 @@ sealed partial class TestStringId :
125125
/// <param name="left">The first instance to compare.</param>
126126
/// <param name="right">The second instance to compare.</param>
127127
/// <returns><c>true</c> if the first instance is less than the second instance; otherwise, <c>false</c>.</returns>
128-
public static bool operator <(TestStringId left, TestStringId right)
128+
public static bool operator <(TestStringId? left, TestStringId? right)
129129
{
130+
if (left is null)
131+
return (right is null ? 0 : -1) < 0;
130132
return left.CompareTo(right) < 0;
131133
}
132134

133135
/// <summary>Determines whether the first instance of <see cref="TestStringId" /> is greater than the second instance.</summary>
134136
/// <param name="left">The first instance to compare.</param>
135137
/// <param name="right">The second instance to compare.</param>
136138
/// <returns><c>true</c> if the first instance is greater than the second instance; otherwise, <c>false</c>.</returns>
137-
public static bool operator >(TestStringId left, TestStringId right)
139+
public static bool operator >(TestStringId? left, TestStringId? right)
138140
{
141+
if (left is null)
142+
return false;
139143
return left.CompareTo(right) > 0;
140144
}
141145

142146
/// <summary>Determines whether the first instance of <see cref="TestStringId" /> is less than or equal to the second instance.</summary>
143147
/// <param name="left">The first instance to compare.</param>
144148
/// <param name="right">The second instance to compare.</param>
145149
/// <returns><c>true</c> if the first instance is less than or equal to the second instance; otherwise, <c>false</c>.</returns>
146-
public static bool operator <=(TestStringId left, TestStringId right)
150+
public static bool operator <=(TestStringId? left, TestStringId? right)
147151
{
152+
if (left is null)
153+
return true;
148154
return left.CompareTo(right) <= 0;
149155
}
150156

151157
/// <summary>Determines whether the first instance of <see cref="TestStringId" /> is greater than or equal to the second instance.</summary>
152158
/// <param name="left">The first instance to compare.</param>
153159
/// <param name="right">The second instance to compare.</param>
154160
/// <returns><c>true</c> if the first instance is greater than or equal to the second instance; otherwise, <c>false</c>.</returns>
155-
public static bool operator >=(TestStringId left, TestStringId right)
161+
public static bool operator >=(TestStringId? left, TestStringId? right)
156162
{
163+
if (left is null)
164+
return (right is null ? 0 : -1) >= 0;
157165
return left.CompareTo(right) >= 0;
158166
}
159167

0 commit comments

Comments
 (0)