Draft code for Chapter 9
MODIFY
src/Chapter09/Listing.09.03.EquivalentRecordStructCode.cs
src/Chapter09/Listing.09.03.EquivalentRecordStructCode.cs
@@ -74,7 +74,7 @@ public readonly struct Angle : IEquatable<Angle>
&& EqualityComparer<string>.Default.Equals(Name, other.Name);
public void Deconstruct(
- out int Degrees, out int Minutes, out int Seconds, string? Name)
+ out int Degrees, out int Minutes, out int Seconds, out string? Name)
{
Degrees = this.Degrees;
Minutes = this.Minutes;

MODIFY
src/Chapter09/Listing.09.04.DeclaringRecordClass.cs
src/Chapter09/Listing.09.04.DeclaringRecordClass.cs
@@ -6,9 +6,3 @@ public record class Coordinate(Angle Longitude, Angle Latitude)
{
public Type ExternalEqualityContract => EqualityContract;
}
-
-
-public record class GeoCoordinate(Angle Longitude, Angle Latitude, string Name) : Coordinate(Longitude, Latitude)
-{
- public new Type ExternalEqualityContract => EqualityContract;
-}

MODIFY
src/Chapter09/Listing.09.05B.EquivalentRecordClassCode.cs
src/Chapter09/Listing.09.05B.EquivalentRecordClassCode.cs
@@ -8,15 +8,10 @@ using System.Text;
[CompilerGenerated]
public class Coordinate : IEquatable<Coordinate>
{
+
public Angle Longitude { get; init; }
public Angle Latitude { get; init; }
- public Coordinate Foo = null;
-
-
-
-
-
public Coordinate(Angle Longitude, Angle Latitude) :
base()
{
@@ -58,8 +53,8 @@ public class Coordinate : IEquatable<Coordinate>
static int GetHashCode(Angle angle) =>
EqualityComparer<Angle>.Default.GetHashCode(angle);
- return (EqualityComparer<Type>.Default.GetHashCode(EqualityContract())
- * -1521134295
+ return (EqualityComparer<Type>.Default.GetHashCode(
+ EqualityContract()) * -1521134295
+ GetHashCode(Longitude)) * -1521134295
+ GetHashCode(Latitude);
}
@@ -70,8 +65,10 @@ public class Coordinate : IEquatable<Coordinate>
public virtual bool Equals(Coordinate? other) =>
(object)this == other || (other is not null
&& EqualityContract() == other!.EqualityContract()
- && EqualityComparer<Angle>.Default.Equals(Longitude, other!.Longitude)
- && EqualityComparer<Angle>.Default.Equals(Latitude, other!.Latitude));
+ && EqualityComparer<Angle>.Default.Equals(
+ Longitude, other!.Longitude)
+ && EqualityComparer<Angle>.Default.Equals(
+ Latitude, other!.Latitude));
public void Deconstruct(out Angle Longitude, out Angle Latitude)
{
@@ -83,8 +80,6 @@ public class Coordinate : IEquatable<Coordinate>
public Type ExternalEqualityContract => EqualityContract();
- public Coordinate Foo1 => Foo;
-
protected Coordinate(Coordinate original)
{
Longitude = original.Longitude;

Draft code for Chapter 9