From 7c40cfa76a4c7bee2225f34936e7a6c4aa4c4bf2 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 9 Aug 2023 10:45:50 -0700 Subject: [PATCH] fix: Implemented changes from Mark Was unsure how to rebase with different file names so pulled off to another branch --- ...isting09.03.ProgrammingWithARecordStruct.cs | 3 +-- .../Listing09.04.EquivalentRecordStructCode.cs | 12 ++++-------- .../Listing09.06.EquivalentRecordClassCode.cs | 18 +++++++++++------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/Chapter09/Listing09.03.ProgrammingWithARecordStruct.cs b/src/Chapter09/Listing09.03.ProgrammingWithARecordStruct.cs index c00d0d569..b26b87dcd 100644 --- a/src/Chapter09/Listing09.03.ProgrammingWithARecordStruct.cs +++ b/src/Chapter09/Listing09.03.ProgrammingWithARecordStruct.cs @@ -9,8 +9,7 @@ public class Program { public static void Main() { - (int degrees, int minutes, int seconds) = ( - 90, 0, 0); + (int degrees, int minutes, int seconds) = (90, 0, 0); // The constructor is generated using positional parameters Angle angle = new(degrees, minutes, seconds); diff --git a/src/Chapter09/Listing09.04.EquivalentRecordStructCode.cs b/src/Chapter09/Listing09.04.EquivalentRecordStructCode.cs index b80974361..ce6e5188a 100644 --- a/src/Chapter09/Listing09.04.EquivalentRecordStructCode.cs +++ b/src/Chapter09/Listing09.04.EquivalentRecordStructCode.cs @@ -72,13 +72,9 @@ public bool Equals(Angle other) => && EqualityComparer.Default.Equals(Seconds, other.Seconds) && EqualityComparer.Default.Equals(Name, other.Name); - public void Deconstruct( - out int Degrees, out int Minutes, out int Seconds, out string? Name) - { - Degrees = this.Degrees; - Minutes = this.Minutes; - Seconds = this.Seconds; - Name = this.Name; - } + public void Deconstruct(out int Degrees, out int Minutes, + out int Seconds, out string? Name) + => (Degrees, Minutes, Seconds, Name) = + (this.Degrees, this.Minutes, this.Seconds, this.Name); } #endregion INCLUDE diff --git a/src/Chapter09/Listing09.06.EquivalentRecordClassCode.cs b/src/Chapter09/Listing09.06.EquivalentRecordClassCode.cs index 320d27b84..693c5c09c 100644 --- a/src/Chapter09/Listing09.06.EquivalentRecordClassCode.cs +++ b/src/Chapter09/Listing09.06.EquivalentRecordClassCode.cs @@ -1,6 +1,7 @@ using AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_02; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_06; + #region INCLUDE using System.Runtime.CompilerServices; using System.Text; @@ -12,8 +13,7 @@ public class Coordinate : IEquatable public Angle Longitude { get; init; } public Angle Latitude { get; init; } - public Coordinate(Angle Longitude, Angle Latitude) : - base() + public Coordinate(Angle Longitude, Angle Latitude) : base() { this.Longitude = Longitude; this.Latitude = Latitude; @@ -42,11 +42,14 @@ protected virtual bool PrintMembers(StringBuilder builder) return true; } - public static bool operator !=(Coordinate? left, Coordinate? right) => - !(left == right); + public static bool operator !=( + Coordinate? left, Coordinate? right) => + !(left == right); - public static bool operator ==(Coordinate? left, Coordinate? right) => - ReferenceEquals(left, right) || (left?.Equals(right) ?? false); + public static bool operator ==( + Coordinate? left, Coordinate? right) => + ReferenceEquals(left, right) || + (left?.Equals(right) ?? false); public override int GetHashCode() { @@ -70,7 +73,8 @@ public virtual bool Equals(Coordinate? other) => && EqualityComparer.Default.Equals( Latitude, other!.Latitude)); - public void Deconstruct(out Angle Longitude, out Angle Latitude) + public void Deconstruct( + out Angle Longitude, out Angle Latitude) { Longitude = this.Longitude; Latitude = this.Latitude;