From a0d5adbfc7247344242a75eb69d2cfd47fe41446 Mon Sep 17 00:00:00 2001 From: Benjamin Michaelis Date: Mon, 9 May 2022 14:06:20 -0700 Subject: [PATCH 01/11] Chapter 12 Regions through 12.6 --- ...eSystemCollectionsStackMethodSignatures.cs | 7 +++-- ...ng12.02.SupportingUndoInEtchASketchGame.cs | 27 +++++++++++++---- ...ing12.03.DefiningASpecializedStackClass.cs | 4 ++- ...ersionsOfVariousValueTypesThatStoreNull.cs | 2 ++ ...eThatContainsAValuePropertyOfTypeObject.cs | 2 ++ ....ImplementingUndoWithAGenericStackClass.cs | 30 ++++++++++++++----- 6 files changed, 55 insertions(+), 17 deletions(-) diff --git a/src/Chapter12/Listing12.01.TheSystemCollectionsStackMethodSignatures.cs b/src/Chapter12/Listing12.01.TheSystemCollectionsStackMethodSignatures.cs index 9ca8799ea..d2db4ee94 100644 --- a/src/Chapter12/Listing12.01.TheSystemCollectionsStackMethodSignatures.cs +++ b/src/Chapter12/Listing12.01.TheSystemCollectionsStackMethodSignatures.cs @@ -1,19 +1,20 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_01 { + #region INCLUDE public class Stack { public virtual object Pop() { - // ... + #region EXCLUDE return new object(); + #endregion EXCLUDE } public virtual void Push(object obj) { // ... } - // ... } - + #endregion INCLUDE } diff --git a/src/Chapter12/Listing12.02.SupportingUndoInEtchASketchGame.cs b/src/Chapter12/Listing12.02.SupportingUndoInEtchASketchGame.cs index dc62ee9c8..42c13d678 100644 --- a/src/Chapter12/Listing12.02.SupportingUndoInEtchASketchGame.cs +++ b/src/Chapter12/Listing12.02.SupportingUndoInEtchASketchGame.cs @@ -1,15 +1,17 @@ -// TODO: Update listing in Manuscript namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_02 { using System; + #region INCLUDE using System.Collections.Generic; public class Program { + #region EXCLUDE public static void Main() { Sketch(); } + #endregion EXCLUDE public static void Sketch() { @@ -18,6 +20,7 @@ public static void Sketch() Cell currentPosition; ConsoleKeyInfo key; // Added in C# 2.0 + #region EXCLUDE Console.WriteLine("Use arrow keys to draw. X to exit."); for(int i = 2; i < Console.WindowHeight; i++) { @@ -27,6 +30,7 @@ public static void Sketch() currentPosition = new Cell(Console.WindowWidth / 2, Console.WindowHeight / 2); path.Push(currentPosition); FillCell(currentPosition); + #endregion EXCLUDE do { @@ -40,7 +44,9 @@ public static void Sketch() // Undo the previous Move if(path.Count >= 1) { + #region HIGHLIGHT currentPosition = (Cell)path.Pop(); + #endregion HIGHLIGHT Console.SetCursorPosition( currentPosition.X, currentPosition.Y); FillCell(currentPosition, ConsoleColor.Black); @@ -48,7 +54,8 @@ public static void Sketch() } break; case ConsoleKey.DownArrow: - if(Console.CursorTop < Console.WindowHeight - 2) + #region EXCLUDE + if (Console.CursorTop < Console.WindowHeight - 2) { currentPosition = new Cell( Console.CursorLeft, Console.CursorTop + 1); @@ -56,8 +63,10 @@ public static void Sketch() path.Push(currentPosition); FillCell(currentPosition); break; + #endregion EXCLUDE case ConsoleKey.UpArrow: - if(Console.CursorTop > 1) + #region EXCLUDE + if (Console.CursorTop > 1) { currentPosition = new Cell( Console.CursorLeft, Console.CursorTop - 1); @@ -65,8 +74,10 @@ public static void Sketch() path.Push(currentPosition); FillCell(currentPosition); break; + #endregion EXCLUDE case ConsoleKey.LeftArrow: - if(Console.CursorLeft > 1) + #region EXCLUDE + if (Console.CursorLeft > 1) { currentPosition = new Cell( Console.CursorLeft - 1, Console.CursorTop); @@ -74,6 +85,7 @@ public static void Sketch() path.Push(currentPosition); FillCell(currentPosition); break; + #endregion EXCLUDE case ConsoleKey.RightArrow: // SaveState() if(Console.CursorLeft < Console.WindowWidth - 2) @@ -81,7 +93,9 @@ public static void Sketch() currentPosition = new Cell( Console.CursorLeft + 1, Console.CursorTop); } + #region HIGHLIGHT path.Push(currentPosition); + #endregion HIGHLIGHT FillCell(currentPosition); break; @@ -89,11 +103,10 @@ public static void Sketch() Console.Beep(); // Added in C# 2.0 break; } - } while(key.Key != ConsoleKey.X); // Use X to quit. } - + #region EXCLUDE private static ConsoleKeyInfo Move() { return Console.ReadKey(true); @@ -117,6 +130,7 @@ private static void FillCell(Cell cell, ConsoleColor color) Console.SetCursorPosition(cell.X, cell.Y); Console.BackgroundColor = ConsoleColor.Black; } + #endregion EXCLUDE } public struct Cell @@ -131,4 +145,5 @@ public Cell(int x, int y) Y = y; } } + #endregion INCLUDE } diff --git a/src/Chapter12/Listing12.03.DefiningASpecializedStackClass.cs b/src/Chapter12/Listing12.03.DefiningASpecializedStackClass.cs index 70a4a5316..ff080fd2d 100644 --- a/src/Chapter12/Listing12.03.DefiningASpecializedStackClass.cs +++ b/src/Chapter12/Listing12.03.DefiningASpecializedStackClass.cs @@ -1,10 +1,12 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_03 { using Listing12_02; - + #region INCLUDE public class CellStack { public virtual object Pop() { return new Cell(); } // would return that last cell added and remove it from the list public virtual void Push(Cell obj) { } + // ... } + #endregion INCLUDE } diff --git a/src/Chapter12/Listing12.04.DeclaringVersionsOfVariousValueTypesThatStoreNull.cs b/src/Chapter12/Listing12.04.DeclaringVersionsOfVariousValueTypesThatStoreNull.cs index 73d78f4ea..270ecc25d 100644 --- a/src/Chapter12/Listing12.04.DeclaringVersionsOfVariousValueTypesThatStoreNull.cs +++ b/src/Chapter12/Listing12.04.DeclaringVersionsOfVariousValueTypesThatStoreNull.cs @@ -2,6 +2,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_04 { using System; + #region INCLUDE struct NullableInt { /// @@ -35,4 +36,5 @@ struct NullableGuid } // ... + #endregion INCLUDE } diff --git a/src/Chapter12/Listing12.05.DeclaringANullableTypeThatContainsAValuePropertyOfTypeObject.cs b/src/Chapter12/Listing12.05.DeclaringANullableTypeThatContainsAValuePropertyOfTypeObject.cs index d12ee9534..6a1993ec7 100644 --- a/src/Chapter12/Listing12.05.DeclaringANullableTypeThatContainsAValuePropertyOfTypeObject.cs +++ b/src/Chapter12/Listing12.05.DeclaringANullableTypeThatContainsAValuePropertyOfTypeObject.cs @@ -1,5 +1,6 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_05 { + #region INCLUDE struct Nullable { /// @@ -15,4 +16,5 @@ struct Nullable // ... } + #endregion INCLUDE } diff --git a/src/Chapter12/Listing12.06.ImplementingUndoWithAGenericStackClass.cs b/src/Chapter12/Listing12.06.ImplementingUndoWithAGenericStackClass.cs index f12f205a4..d80cfbfaf 100644 --- a/src/Chapter12/Listing12.06.ImplementingUndoWithAGenericStackClass.cs +++ b/src/Chapter12/Listing12.06.ImplementingUndoWithAGenericStackClass.cs @@ -1,22 +1,26 @@ -// TODO: Update listing in Manuscript namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_06 { + #region INCLUDE using System; using System.Collections.Generic; public class Program { + #region EXCLUDE public static void Main() { Sketch(); } + #endregion EXCLUDE public static void Sketch() { + #region HIGHLIGHT Stack path = new Stack(); + #endregion HIGHLIGHT Cell currentPosition; ConsoleKeyInfo key; // Added in C# 2.0 - + #region EXCLUDE Console.WriteLine("Use arrow keys to draw. X to exit."); for(int i = 2; i < Console.WindowHeight; i++) { @@ -26,6 +30,7 @@ public static void Sketch() currentPosition = new Cell(Console.WindowWidth / 2, Console.WindowHeight / 2); path.Push(currentPosition); FillCell(currentPosition); + #endregion EXCLUDE do { @@ -39,8 +44,10 @@ public static void Sketch() // Undo the previous Move if(path.Count >= 1) { + #region HIGHLIGHT // No cast required currentPosition = path.Pop(); + #endregion HIGHLIGHT Console.SetCursorPosition( currentPosition.X, currentPosition.Y); FillCell(currentPosition, ConsoleColor.Black); @@ -48,7 +55,8 @@ public static void Sketch() } break; case ConsoleKey.DownArrow: - if(Console.CursorTop < Console.WindowHeight - 2) + #region EXCLUDE + if (Console.CursorTop < Console.WindowHeight - 2) { currentPosition = new Cell( Console.CursorLeft, Console.CursorTop + 1); @@ -57,8 +65,10 @@ public static void Sketch() path.Push(currentPosition); FillCell(currentPosition); break; + #endregion EXCLUDE case ConsoleKey.UpArrow: - if(Console.CursorTop > 1) + #region EXCLUDE + if (Console.CursorTop > 1) { currentPosition = new Cell( Console.CursorLeft, Console.CursorTop - 1); @@ -67,8 +77,10 @@ public static void Sketch() path.Push(currentPosition); FillCell(currentPosition); break; + #endregion EXCLUDE case ConsoleKey.LeftArrow: - if(Console.CursorLeft > 1) + #region EXCLUDE + if (Console.CursorLeft > 1) { currentPosition = new Cell( Console.CursorLeft - 1, Console.CursorTop); @@ -77,6 +89,7 @@ public static void Sketch() path.Push(currentPosition); FillCell(currentPosition); break; + #endregion EXCLUDE case ConsoleKey.RightArrow: // SaveState() if(Console.CursorLeft < Console.WindowWidth - 2) @@ -84,8 +97,10 @@ public static void Sketch() currentPosition = new Cell( Console.CursorLeft + 1, Console.CursorTop); } + #region HIGHLIGHT // Only type Cell allowed in call to Push() path.Push(currentPosition); + #endregion HIGHLIGHT FillCell(currentPosition); break; @@ -97,7 +112,7 @@ public static void Sketch() } while(key.Key != ConsoleKey.X); // Use X to quit } - + #region EXCLUDE private static ConsoleKeyInfo Move() { return Console.ReadKey(true); @@ -121,8 +136,9 @@ private static void FillCell(Cell cell, ConsoleColor color) Console.SetCursorPosition(cell.X, cell.Y); Console.BackgroundColor = ConsoleColor.Black; } + #endregion EXCLUDE } - + #endregion INCLUDE public struct Cell { readonly public int X; From ef0c0e3a01651b6b01fa6286fbb005150b4206e3 Mon Sep 17 00:00:00 2001 From: Benjamin Michaelis Date: Mon, 9 May 2022 14:17:36 -0700 Subject: [PATCH 02/11] Regions through 12.13 --- ...isting12.07.DeclaringAGenericClassStack.cs | 5 +++- ...Listing12.08.DeclaringAGenericInterface.cs | 2 ++ ...ting12.09.ImplementingAGenericInterface.cs | 4 ++-- ...AnInterfaceImplementationOnASingleClass.cs | 24 ++++++++++++------- ...g12.11.DeclaringAGenericTypeConstructor.cs | 7 +++--- ...itializingAllFieldsCasuingACompileError.cs | 6 +++-- ...nitializingAFieldWithTheDefaultOperator.cs | 20 +++++++++++----- 7 files changed, 45 insertions(+), 23 deletions(-) diff --git a/src/Chapter12/Listing12.07.DeclaringAGenericClassStack.cs b/src/Chapter12/Listing12.07.DeclaringAGenericClassStack.cs index c37e0604d..a5a746ad6 100644 --- a/src/Chapter12/Listing12.07.DeclaringAGenericClassStack.cs +++ b/src/Chapter12/Listing12.07.DeclaringAGenericClassStack.cs @@ -1,5 +1,6 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_07 { + #region INCLUDE public class Stack { public Stack(int maxSize) @@ -17,8 +18,10 @@ public void Push(T data) public T Pop() { - //... + #region EXCLUDE return InternalItems[0]; //just for the example + #endregion EXCLUDE } } + #endregion INCLUDE } diff --git a/src/Chapter12/Listing12.08.DeclaringAGenericInterface.cs b/src/Chapter12/Listing12.08.DeclaringAGenericInterface.cs index f4d393dfa..9788e51c6 100644 --- a/src/Chapter12/Listing12.08.DeclaringAGenericInterface.cs +++ b/src/Chapter12/Listing12.08.DeclaringAGenericInterface.cs @@ -1,8 +1,10 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_08 { + #region INCLUDE interface IPair { T First { get; set; } T Second { get; set; } } + #endregion INCLUDE } diff --git a/src/Chapter12/Listing12.09.ImplementingAGenericInterface.cs b/src/Chapter12/Listing12.09.ImplementingAGenericInterface.cs index 407a1188a..10fc6124c 100644 --- a/src/Chapter12/Listing12.09.ImplementingAGenericInterface.cs +++ b/src/Chapter12/Listing12.09.ImplementingAGenericInterface.cs @@ -1,11 +1,11 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_09 { using Listing12_08; - + #region INCLUDE public struct Pair : IPair { public T First { get; set; } public T Second { get; set; } } - + #endregion INCLUDE } diff --git a/src/Chapter12/Listing12.10.DuplicatingAnInterfaceImplementationOnASingleClass.cs b/src/Chapter12/Listing12.10.DuplicatingAnInterfaceImplementationOnASingleClass.cs index 125952639..46d1da245 100644 --- a/src/Chapter12/Listing12.10.DuplicatingAnInterfaceImplementationOnASingleClass.cs +++ b/src/Chapter12/Listing12.10.DuplicatingAnInterfaceImplementationOnASingleClass.cs @@ -1,49 +1,54 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_10 { using System.Collections.Generic; - + #region INCLUDE public interface IContainer { - ICollection Items - { - get; - set; - } + ICollection Items { get; set; } } public class Person : IContainer
, IContainer, IContainer { + #region HIGHLIGHT ICollection
IContainer
.Items + #endregion HIGHLIGHT { get { - //... + #region EXCLUDE return new List
(); + #endregion EXCLUDE } set { //... } } + #region HIGHLIGHT ICollection IContainer.Items + #endregion HIGHLIGHT { get { - //... + #region EXCLUDE return new List(); + #endregion EXCLUDE } set { //... } } + #region HIGHLIGHT ICollection IContainer.Items + #endregion HIGHLIGHT { get { - //... + #region EXCLUDE return new List(); + #endregion EXCLUDE } set { @@ -51,6 +56,7 @@ ICollection IContainer.Items } } } + #endregion INCLUDE public class Address { } // For example purposes only public class Phone { } // For example purposes only diff --git a/src/Chapter12/Listing12.11.DeclaringAGenericTypeConstructor.cs b/src/Chapter12/Listing12.11.DeclaringAGenericTypeConstructor.cs index 1ca5fb059..5e6a3418e 100644 --- a/src/Chapter12/Listing12.11.DeclaringAGenericTypeConstructor.cs +++ b/src/Chapter12/Listing12.11.DeclaringAGenericTypeConstructor.cs @@ -1,18 +1,19 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_11 { using Listing12_08; - + #region INCLUDE public struct Pair : IPair { + #region HIGHLIGHT public Pair(T first, T second) { First = first; Second = second; } + #endregion HIGHLIGHT public T First { get; set; } public T Second { get; set; } - - } + #endregion INCLUDE } diff --git a/src/Chapter12/Listing12.12.NotInitializingAllFieldsCasuingACompileError.cs b/src/Chapter12/Listing12.12.NotInitializingAllFieldsCasuingACompileError.cs index 8d9893771..377bc78c4 100644 --- a/src/Chapter12/Listing12.12.NotInitializingAllFieldsCasuingACompileError.cs +++ b/src/Chapter12/Listing12.12.NotInitializingAllFieldsCasuingACompileError.cs @@ -1,7 +1,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_12 { using Listing12_08; - + #region INCLUDE public struct Pair : IPair { // ERROR: Field 'Pair.Second' must be fully assigned @@ -11,6 +11,7 @@ public struct Pair : IPair // First = first; // } + #region EXCLUDE public Pair(T first, T second) { First = first; @@ -19,6 +20,7 @@ public Pair(T first, T second) public T First { get; set; } public T Second { get; set; } - + #endregion EXCLUDE } + #endregion INCLUDE } diff --git a/src/Chapter12/Listing12.13.InitializingAFieldWithTheDefaultOperator.cs b/src/Chapter12/Listing12.13.InitializingAFieldWithTheDefaultOperator.cs index 124914c24..9a8ae4715 100644 --- a/src/Chapter12/Listing12.13.InitializingAFieldWithTheDefaultOperator.cs +++ b/src/Chapter12/Listing12.13.InitializingAFieldWithTheDefaultOperator.cs @@ -4,19 +4,25 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_13 { using Listing12_08; - + #region INCLUDE public struct Pair : IPair { public Pair(T first) { First = first; -// Justifiction: Ignore warning pending struct/class constraints, later on in the chapter, -// so that Second can be declared as T?. -#pragma warning disable CS8601 // Possible null reference assignment. + #region EXCLUDE + // Justifiction: Ignore warning pending struct/class constraints, later on in the chapter, + // so that Second can be declared as T?. + #pragma warning disable CS8601 // Possible null reference assignment. + #endregion EXCLUDE + #region HIGHLIGHT Second = default; -#pragma warning restore CS8601 // Possible null reference assignment. + #endregion HIGHLIGHT + #region EXCLUDE + #pragma warning restore CS8601 // Possible null reference assignment. + #endregion EXCLUDE } - + #region EXCLUDE public Pair(T first, T second) { First = first; @@ -25,5 +31,7 @@ public Pair(T first, T second) public T First { get; set; } public T Second { get; set; } + #endregion EXCLUDE } + #endregion INCLUDE } From a821b28f86252015716e8a6b93c4c0857caa9f11 Mon Sep 17 00:00:00 2001 From: Benjamin Michaelis Date: Thu, 12 May 2022 18:04:40 -0700 Subject: [PATCH 03/11] Regions through Chapter 12.23 --- ...aringAGenericWithMultipleTypeParameters.cs | 3 ++- ...15.UsingATypewithMultipleTypeParameters.cs | 2 ++ ....16.UsingArityToOverloadATypeDefinition.cs | 2 ++ ...SystemValueTupleInstantiationApproaches.cs | 8 +++++--- .../Listing12.18.NestedGenericTypes.cs | 7 +++++-- ...laringABinaryTreeClassWithNoConstraints.cs | 3 ++- ...ingTheTypeParameterToSupportAnInterface.cs | 8 +++++--- ...erToSupportAnInterfaceOrExceptionThrown.cs | 20 +++++++++++++++---- ...ing12.22.DeclaringAnInterfaceConstraint.cs | 20 +++++++++++++++---- ...ting12.23.DeclaringABaseClassConstraint.cs | 9 ++++++--- 10 files changed, 61 insertions(+), 21 deletions(-) diff --git a/src/Chapter12/Listing12.14.DeclaringAGenericWithMultipleTypeParameters.cs b/src/Chapter12/Listing12.14.DeclaringAGenericWithMultipleTypeParameters.cs index efacde5e8..a4588a362 100644 --- a/src/Chapter12/Listing12.14.DeclaringAGenericWithMultipleTypeParameters.cs +++ b/src/Chapter12/Listing12.14.DeclaringAGenericWithMultipleTypeParameters.cs @@ -1,5 +1,6 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_14 { + #region INCLUDE interface IPair { TFirst First { get; set; } @@ -16,6 +17,6 @@ public Pair(TFirst first, TSecond second) public TFirst First { get; set; } public TSecond Second { get; set; } - } + #endregion INCLUDE } diff --git a/src/Chapter12/Listing12.15.UsingATypewithMultipleTypeParameters.cs b/src/Chapter12/Listing12.15.UsingATypewithMultipleTypeParameters.cs index 4fd44565a..81addde66 100644 --- a/src/Chapter12/Listing12.15.UsingATypewithMultipleTypeParameters.cs +++ b/src/Chapter12/Listing12.15.UsingATypewithMultipleTypeParameters.cs @@ -7,12 +7,14 @@ public class Program { public static void Main() { + #region INCLUDE Pair historicalEvent = new Pair(1914, "Shackleton leaves for South Pole on ship Endurance"); Console.WriteLine("{0}: {1}", historicalEvent.First, historicalEvent.Second); + #endregion INCLUDE } } } diff --git a/src/Chapter12/Listing12.16.UsingArityToOverloadATypeDefinition.cs b/src/Chapter12/Listing12.16.UsingArityToOverloadATypeDefinition.cs index 45cb78690..31025ee53 100644 --- a/src/Chapter12/Listing12.16.UsingArityToOverloadATypeDefinition.cs +++ b/src/Chapter12/Listing12.16.UsingArityToOverloadATypeDefinition.cs @@ -1,5 +1,6 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_16 { + #region INCLUDE public class Tuple { // ... @@ -36,4 +37,5 @@ public class Tuple // : IStructuralEquatable, { // ... } + #endregion INCLUDE } diff --git a/src/Chapter12/Listing12.17.ComparingSystemValueTupleInstantiationApproaches.cs b/src/Chapter12/Listing12.17.ComparingSystemValueTupleInstantiationApproaches.cs index 642f2361b..35fc3f002 100644 --- a/src/Chapter12/Listing12.17.ComparingSystemValueTupleInstantiationApproaches.cs +++ b/src/Chapter12/Listing12.17.ComparingSystemValueTupleInstantiationApproaches.cs @@ -8,11 +8,12 @@ public class Program { public static void Main() { -#if !PRECSHARP7 + #region INCLUDE + #if !PRECSHARP7 (string, Contact) keyValuePair; keyValuePair = ("555-55-5555", new Contact("Inigo Montoya")); -#elif CSHARP6 + #elif CSHARP6 ValueTuple keyValuePair; keyValuePair = new ValueTuple( @@ -20,7 +21,8 @@ public static void Main() keyValuePair = ValueTuple.Create( "555-55-5555", new Contact("Inigo Montoya")); -#endif // !PRECSHARP7 + #endif // !PRECSHARP7 + #endregion INCLUDE } } } diff --git a/src/Chapter12/Listing12.18.NestedGenericTypes.cs b/src/Chapter12/Listing12.18.NestedGenericTypes.cs index 457eaddf4..3c0a50ce6 100644 --- a/src/Chapter12/Listing12.18.NestedGenericTypes.cs +++ b/src/Chapter12/Listing12.18.NestedGenericTypes.cs @@ -1,7 +1,8 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_18 { #pragma warning disable 0693 // Disabled warning due to nested type parameter - // with overlapping name + // with overlapping name + #region INCLUDE class Container { // Nested classes inherit type parameter @@ -9,10 +10,12 @@ class Container // a warning class Nested { - // TODO: Update listing in Manuscript + #region HIGHLIGHT static void Method(T param0, U param1) + #endregion HIGHLIGHT { } } } + #endregion INCLUDE } diff --git a/src/Chapter12/Listing12.19.DeclaringABinaryTreeClassWithNoConstraints.cs b/src/Chapter12/Listing12.19.DeclaringABinaryTreeClassWithNoConstraints.cs index 0eca57443..66c2f7307 100644 --- a/src/Chapter12/Listing12.19.DeclaringABinaryTreeClassWithNoConstraints.cs +++ b/src/Chapter12/Listing12.19.DeclaringABinaryTreeClassWithNoConstraints.cs @@ -1,7 +1,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_19 { using Listing12_13; - + #region INCLUDE public class BinaryTree { public BinaryTree(T item) @@ -12,4 +12,5 @@ public BinaryTree(T item) public T Item { get; set; } public Pair> SubItems { get; set; } } + #endregion INCLUDE } diff --git a/src/Chapter12/Listing12.20.NeedingTheTypeParameterToSupportAnInterface.cs b/src/Chapter12/Listing12.20.NeedingTheTypeParameterToSupportAnInterface.cs index 3ddf1e972..65c3e1fc6 100644 --- a/src/Chapter12/Listing12.20.NeedingTheTypeParameterToSupportAnInterface.cs +++ b/src/Chapter12/Listing12.20.NeedingTheTypeParameterToSupportAnInterface.cs @@ -2,9 +2,9 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_20 { using System; using Listing12_13; -// In an actual implementation Item would be used to hold some value + // In an actual implementation Item would be used to hold some value #pragma warning disable CS0168 - + #region INCLUDE public class BinaryTree { public BinaryTree(T item) @@ -13,12 +13,12 @@ public BinaryTree(T item) } public T Item { get; set; } - public Pair> SubItems { get { return _SubItems; } set { + #region INCLUDE IComparable first; // ERROR: Cannot implicitly convert type... //first = value.First; // Explicit cast required @@ -35,9 +35,11 @@ public Pair> SubItems // //... //} _SubItems = value; + #endregion INCLUDE } } private Pair> _SubItems; } + #endregion INCLUDE #pragma warning restore CS0168 } diff --git a/src/Chapter12/Listing12.21.NeedingTheTypeParameterToSupportAnInterfaceOrExceptionThrown.cs b/src/Chapter12/Listing12.21.NeedingTheTypeParameterToSupportAnInterfaceOrExceptionThrown.cs index 9b7b5ca18..c770a1115 100644 --- a/src/Chapter12/Listing12.21.NeedingTheTypeParameterToSupportAnInterfaceOrExceptionThrown.cs +++ b/src/Chapter12/Listing12.21.NeedingTheTypeParameterToSupportAnInterfaceOrExceptionThrown.cs @@ -2,7 +2,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_21 { using System; using Listing12_13; - + #region INCLUDE public class BinaryTree { public BinaryTree(T item) @@ -18,16 +18,27 @@ public Pair?>? SubItems { switch (value) { + // Null handling removed for elucidation + + // Using C# 8.0 Pattern Matching. Switch to + // checking for null prior to C# 8.0 + #region EXCLUDE case { First: null}: // First is null break; case { Second: null }: // Second is null break; - case { - First: {Item: IComparable first }, + #endregion EXCLUDE + case + { + #region HIGHLIGHT + First: {Item: IComparable first }, + #endregion HIGHLIGHT Second: {Item: T second } }: - if(first.CompareTo(second) < 0) + #region HIGHLIGHT + if (first.CompareTo(second) < 0) + #endregion HIGHLIGHT { // first is less than second } @@ -46,4 +57,5 @@ public Pair?>? SubItems } private Pair?>? _SubItems; } + #endregion INCLUDE } diff --git a/src/Chapter12/Listing12.22.DeclaringAnInterfaceConstraint.cs b/src/Chapter12/Listing12.22.DeclaringAnInterfaceConstraint.cs index c638c51ad..5b243e6e2 100644 --- a/src/Chapter12/Listing12.22.DeclaringAnInterfaceConstraint.cs +++ b/src/Chapter12/Listing12.22.DeclaringAnInterfaceConstraint.cs @@ -3,8 +3,11 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_22 using System; using Listing12_13; + #region INCLUDE public class BinaryTree + #region HIGHLIGHT where T : System.IComparable + #endregion HIGHLIGHT { public BinaryTree(T item) { @@ -12,26 +15,35 @@ public BinaryTree(T item) } public T Item { get; set; } - - public Pair> SubItems + public Pair?>? SubItems { get { return _SubItems; } set { switch (value) { + // Null handling removed for elucidation + + // Using C# 8.0 Pattern Matching. Switch to + // checking for null prior to C# 8.0 + #region EXCLUDE case { First: null }: // First is null break; case { Second: null }: // Second is null break; + #endregion EXCLUDE case { + #region HIGHLIGHT First: { Item: T first }, + #endregion HIGHLIGHT Second: { Item: T second } }: + #region HIGHLIGHT if (first.CompareTo(second) < 0) + #endregion HIGHLIGHT { // first is less than second } @@ -48,7 +60,7 @@ public Pair> SubItems _SubItems = value; } } - private Pair> _SubItems; - + private Pair?>? _SubItems; } + #endregion INCLUDE } diff --git a/src/Chapter12/Listing12.23.DeclaringABaseClassConstraint.cs b/src/Chapter12/Listing12.23.DeclaringABaseClassConstraint.cs index 11540d640..5f9d3b504 100644 --- a/src/Chapter12/Listing12.23.DeclaringABaseClassConstraint.cs +++ b/src/Chapter12/Listing12.23.DeclaringABaseClassConstraint.cs @@ -1,13 +1,16 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_23 { + #region INCLUDE public class EntityDictionary : System.Collections.Generic.Dictionary - where TKey: notnull + #region HIGHLIGHT + where TKey : notnull where TValue : EntityBase + #endregion HIGHLIGHT { - //... + // ... } - + #endregion INCLUDE public class EntityBase { } From 01956d6ddbc18a181776ef4e7000ef745b51cfb1 Mon Sep 17 00:00:00 2001 From: Benjamin Michaelis Date: Fri, 13 May 2022 09:01:10 -0700 Subject: [PATCH 04/11] Through 12.30 --- ...GenericWithAMulticastDelegateConstraint.cs | 2 ++ ....SpecifyingTheTypeParameterAsAValueType.cs | 16 ++++++++++++-- ...ting12.26.SpecifyingMultipleConstraints.cs | 3 ++- ....RequiringADefaultConstructorConstraint.cs | 13 ++++++----- ...anOnlyBeSpecifiedForDefaultConstructors.cs | 22 +++++++++++-------- ...nterfaceInPlaceOfAConstructorConstraint.cs | 20 ++++++++++++----- ...aringAnEntityToBeUsedInEntityDictionary.cs | 3 ++- 7 files changed, 56 insertions(+), 23 deletions(-) diff --git a/src/Chapter12/Listing12.24.DeclaringAGenericWithAMulticastDelegateConstraint.cs b/src/Chapter12/Listing12.24.DeclaringAGenericWithAMulticastDelegateConstraint.cs index 500801693..fa50ea979 100644 --- a/src/Chapter12/Listing12.24.DeclaringAGenericWithAMulticastDelegateConstraint.cs +++ b/src/Chapter12/Listing12.24.DeclaringAGenericWithAMulticastDelegateConstraint.cs @@ -4,6 +4,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_31 { public class Publisher { + #region INCLUDE static public object? InvokeAll( object?[]? args, params TDelegate[] delegates) // Constraint of type Action/Func not allowed @@ -20,6 +21,7 @@ public class Publisher return null; }; } + #endregion INCLUDE static public void InvokeAll(params Action?[] actions) { diff --git a/src/Chapter12/Listing12.25.SpecifyingTheTypeParameterAsAValueType.cs b/src/Chapter12/Listing12.25.SpecifyingTheTypeParameterAsAValueType.cs index 0ec1788d2..12800ab36 100644 --- a/src/Chapter12/Listing12.25.SpecifyingTheTypeParameterAsAValueType.cs +++ b/src/Chapter12/Listing12.25.SpecifyingTheTypeParameterAsAValueType.cs @@ -1,13 +1,24 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_24 { using System; - + #region INCLUDE public struct Nullable : IFormattable, IComparable, IComparable>, INullable + #region HIGHLIGHT where T : struct + #endregion HIGHLIGHT { // ... + public static implicit operator Nullable(T value) => + new Nullable(value); + public static explicit operator T(Nullable value) => value!.Value; + #region EXCLUDE + public Nullable(T value) + { + // ... + } + public T Value => throw new NotImplementedException(); public string ToString(string? format, IFormatProvider? formatProvider) { throw new NotImplementedException(); @@ -27,6 +38,7 @@ public bool IsNull { get { throw new NotImplementedException(); } } + #endregion EXCLUDE } - + #endregion INCLUDE } diff --git a/src/Chapter12/Listing12.26.SpecifyingMultipleConstraints.cs b/src/Chapter12/Listing12.26.SpecifyingMultipleConstraints.cs index 0013bd9c8..3db641076 100644 --- a/src/Chapter12/Listing12.26.SpecifyingMultipleConstraints.cs +++ b/src/Chapter12/Listing12.26.SpecifyingMultipleConstraints.cs @@ -3,7 +3,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_25 using System; using System.Collections.Generic; using Listing12_23; - + #region INCLUDE public class EntityDictionary : Dictionary where TKey : IComparable, IFormattable @@ -11,4 +11,5 @@ public class EntityDictionary { // ... } + #endregion INCLUDE } diff --git a/src/Chapter12/Listing12.27.RequiringADefaultConstructorConstraint.cs b/src/Chapter12/Listing12.27.RequiringADefaultConstructorConstraint.cs index 9db9e4bb2..4f15d2820 100644 --- a/src/Chapter12/Listing12.27.RequiringADefaultConstructorConstraint.cs +++ b/src/Chapter12/Listing12.27.RequiringADefaultConstructorConstraint.cs @@ -2,29 +2,31 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_26 { using System; using System.Collections.Generic; - + #region INCLUDE public class EntityBase where TKey: notnull { - public TKey Key { get; set; } - public EntityBase(TKey key) { Key = key; } + + public TKey Key { get; set; } } public class EntityDictionary : Dictionary where TKey : IComparable, IFormattable + #region HIGHLIGHT where TValue : EntityBase, new() + #endregion HIGHLIGHT { - // ... - public TValue MakeValue(TKey key) { + #region HIGHLIGHT TValue newEntity = new TValue { + #endregion HIGHLIGHT Key = key }; Add(newEntity.Key, newEntity); @@ -33,4 +35,5 @@ public TValue MakeValue(TKey key) // ... } + #endregion INCLUDE } diff --git a/src/Chapter12/Listing12.28.ConstraintsCanOnlyBeSpecifiedForDefaultConstructors.cs b/src/Chapter12/Listing12.28.ConstraintsCanOnlyBeSpecifiedForDefaultConstructors.cs index b212b6fd6..5e917c547 100644 --- a/src/Chapter12/Listing12.28.ConstraintsCanOnlyBeSpecifiedForDefaultConstructors.cs +++ b/src/Chapter12/Listing12.28.ConstraintsCanOnlyBeSpecifiedForDefaultConstructors.cs @@ -2,14 +2,18 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_28 { public class Program { - //public TValue New(TKey key) - //{ - // // Error: 'TValue': Cannot provide arguments - // // when creating an instance of a variable type - // TValue newEntity = null; - // // newEntity = new TValue(key); - // Add(newEntity.Key, newEntity); - // return newEntity; - //} + /* + #region INCLUDE + public TValue New(TKey key) + { + // Error: 'TValue': Cannot provide arguments + // when creating an instance of a variable type + TValue newEntity = null; + // newEntity = new TValue(key); + Add(newEntity.Key, newEntity); + return newEntity; + } + #endregion INCLUDE + */ } } diff --git a/src/Chapter12/Listing12.29.UsingAFactoryInterfaceInPlaceOfAConstructorConstraint.cs b/src/Chapter12/Listing12.29.UsingAFactoryInterfaceInPlaceOfAConstructorConstraint.cs index b16e291d6..34420522c 100644 --- a/src/Chapter12/Listing12.29.UsingAFactoryInterfaceInPlaceOfAConstructorConstraint.cs +++ b/src/Chapter12/Listing12.29.UsingAFactoryInterfaceInPlaceOfAConstructorConstraint.cs @@ -3,35 +3,45 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_29 using System.Collections.Generic; using System; + #region INCLUDE public class EntityBase { + #region HIGHLIGHT public EntityBase(TKey key) { Key = key; } + #endregion HIGHLIGHT public TKey Key { get; set; } } - public interface IEntityFactory - { - TValue CreateNew(TKey key); - } - public class EntityDictionary : Dictionary where TKey : IComparable, IFormattable + #region HIGHLIGHT where TValue : EntityBase where TFactory : IEntityFactory, new() + #endregion HIGHLIGHT { // ... public TValue New(TKey key) { TFactory factory = new TFactory(); + #region HIGHLIGHT TValue newEntity = factory.CreateNew(key); + #endregion HIGHLIGHT Add(newEntity.Key, newEntity); return newEntity; } //... } + + #region HIGHLIGHT + public interface IEntityFactory + { + TValue CreateNew(TKey key); + } + #endregion HIGHLIGHT + #endregion INCLUDE } diff --git a/src/Chapter12/Listing12.30.DeclaringAnEntityToBeUsedInEntityDictionary.cs b/src/Chapter12/Listing12.30.DeclaringAnEntityToBeUsedInEntityDictionary.cs index a2aa852c0..0d764c916 100644 --- a/src/Chapter12/Listing12.30.DeclaringAnEntityToBeUsedInEntityDictionary.cs +++ b/src/Chapter12/Listing12.30.DeclaringAnEntityToBeUsedInEntityDictionary.cs @@ -2,7 +2,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_30 { using System; using Listing12_29; - + #region INCLUDE public class Order : EntityBase { public Order(Guid key) : @@ -19,4 +19,5 @@ public Order CreateNew(Guid key) return new Order(key); } } + #endregion INCLUDE } From 761fe0d3a184e484756e640359db5b95e67d7336 Mon Sep 17 00:00:00 2001 From: Benjamin Michaelis Date: Mon, 23 May 2022 12:22:20 -0700 Subject: [PATCH 05/11] Finish up chapter 12 --- ...ing12.22.DeclaringAnInterfaceConstraint.cs | 4 ++-- ...InheritedConstraintsSpecifiedExplicitly.cs | 5 +++-- ...ngInheritedOnVirtualMembersIsProhibited.cs | 8 ++++---- ...traintExpressionsCannotRequireOperators.cs | 8 ++++++-- ...onstraintsUsingOrRelationshipNotAllowed.cs | 4 +++- .../Listing12.35.DefiningGenericMethods.cs | 2 ++ ...36.SpecifyingTheTypeParameterExplicitly.cs | 2 ++ .../Listing12.37.InferringTheTypeParameter.cs | 2 ++ ...8.SpecifyingConstraintsOnGenericMethods.cs | 4 ++++ ...yTreeRequiringIComparableTypeParameters.cs | 4 ++++ ...weenGenericsWithDifferentTypeParameters.cs | 3 ++- ...reventingCovarianceMaintainsHomogeneity.cs | 6 +++++- ...ting12.42.PotentiallyPossibleCovariance.cs | 9 +++++++-- ...arianceUsingTheOutTypeParameterModifier.cs | 4 ++++ ...varianceUsingTheInTypeParameterModifier.cs | 14 ++++++++------ ...sting12.45.CompilerValidationOfVariance.cs | 15 +++++---------- .../Listing12.46.StackDeclaration.cs | 11 +++++------ src/Chapter12/Listing12.47.CILCodeForStack.cs | 17 ++++++++++------- ...ng12.48.CILWithExclamationPointNotation.cs | 19 +++++++++++-------- .../Listing12.49.StackIntDefinition.cs | 3 ++- ...ting12.50.DeclaringVariablesOfTypeStack.cs | 2 ++ 21 files changed, 93 insertions(+), 53 deletions(-) diff --git a/src/Chapter12/Listing12.22.DeclaringAnInterfaceConstraint.cs b/src/Chapter12/Listing12.22.DeclaringAnInterfaceConstraint.cs index 5b243e6e2..c4ead753b 100644 --- a/src/Chapter12/Listing12.22.DeclaringAnInterfaceConstraint.cs +++ b/src/Chapter12/Listing12.22.DeclaringAnInterfaceConstraint.cs @@ -15,7 +15,7 @@ public BinaryTree(T item) } public T Item { get; set; } - public Pair?>? SubItems + public Pair?> SubItems { get { return _SubItems; } set @@ -60,7 +60,7 @@ public Pair?>? SubItems _SubItems = value; } } - private Pair?>? _SubItems; + private Pair?> _SubItems; } #endregion INCLUDE } diff --git a/src/Chapter12/Listing12.31.InheritedConstraintsSpecifiedExplicitly.cs b/src/Chapter12/Listing12.31.InheritedConstraintsSpecifiedExplicitly.cs index ef56993c8..59939bb84 100644 --- a/src/Chapter12/Listing12.31.InheritedConstraintsSpecifiedExplicitly.cs +++ b/src/Chapter12/Listing12.31.InheritedConstraintsSpecifiedExplicitly.cs @@ -1,8 +1,8 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_31 { using System; - - class EntityBase where T : IComparable + #region INCLUDE + public class EntityBase where T : IComparable { // ... } @@ -15,4 +15,5 @@ class EntityBase where T : IComparable // { // ... // } + #endregion INCLUDE } diff --git a/src/Chapter12/Listing12.32.RepeatingInheritedOnVirtualMembersIsProhibited.cs b/src/Chapter12/Listing12.32.RepeatingInheritedOnVirtualMembersIsProhibited.cs index ed98e69f0..8ca0dda0b 100644 --- a/src/Chapter12/Listing12.32.RepeatingInheritedOnVirtualMembersIsProhibited.cs +++ b/src/Chapter12/Listing12.32.RepeatingInheritedOnVirtualMembersIsProhibited.cs @@ -1,8 +1,8 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_32 { using System; - - class EntityBase + #region INCLUDE + public class EntityBase { public virtual void Method(T t) where T : IComparable @@ -10,7 +10,7 @@ public virtual void Method(T t) // ... } } - class Order : EntityBase + public class Order : EntityBase { public override void Method(T t) // Constraints may not be repeated on overriding @@ -20,5 +20,5 @@ public override void Method(T t) // ... } } - + #endregion INCLUDE } diff --git a/src/Chapter12/Listing12.33.ConstraintExpressionsCannotRequireOperators.cs b/src/Chapter12/Listing12.33.ConstraintExpressionsCannotRequireOperators.cs index 293518858..7efa89605 100644 --- a/src/Chapter12/Listing12.33.ConstraintExpressionsCannotRequireOperators.cs +++ b/src/Chapter12/Listing12.33.ConstraintExpressionsCannotRequireOperators.cs @@ -1,14 +1,18 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_33 { + /* + #region INCLUDE public abstract class MathEx { -#if INVALID_CODE public static T Add(T first, T second) { // Error: Operator '+' cannot be applied to // operands of type 'T' and 'T' + #region HIGHLIGHT // return first + second; + #endregion HIGHLIGHT } -#endif } + #endregion INCLUDE + */ } diff --git a/src/Chapter12/Listing12.34.CombiningConstraintsUsingOrRelationshipNotAllowed.cs b/src/Chapter12/Listing12.34.CombiningConstraintsUsingOrRelationshipNotAllowed.cs index 6425116fc..33e10c1a0 100644 --- a/src/Chapter12/Listing12.34.CombiningConstraintsUsingOrRelationshipNotAllowed.cs +++ b/src/Chapter12/Listing12.34.CombiningConstraintsUsingOrRelationshipNotAllowed.cs @@ -1,9 +1,11 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_30 { + #region INCLUDE public class BinaryTree // Error: OR is not supported - //where T: System.IComparable || System.IFormattable + // where T: System.IComparable || System.IFormattable { // ... } + #endregion INCLUDE } diff --git a/src/Chapter12/Listing12.35.DefiningGenericMethods.cs b/src/Chapter12/Listing12.35.DefiningGenericMethods.cs index 6813fe9d4..ea282d1a0 100644 --- a/src/Chapter12/Listing12.35.DefiningGenericMethods.cs +++ b/src/Chapter12/Listing12.35.DefiningGenericMethods.cs @@ -2,6 +2,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_35 { using System; + #region INCLUDE public static class MathEx { public static T Max(T first, params T[] values) @@ -33,4 +34,5 @@ public static T Min(T first, params T[] values) return minimum; } } + #endregion INCLUDE } diff --git a/src/Chapter12/Listing12.36.SpecifyingTheTypeParameterExplicitly.cs b/src/Chapter12/Listing12.36.SpecifyingTheTypeParameterExplicitly.cs index 2e06baffd..fcd40ef34 100644 --- a/src/Chapter12/Listing12.36.SpecifyingTheTypeParameterExplicitly.cs +++ b/src/Chapter12/Listing12.36.SpecifyingTheTypeParameterExplicitly.cs @@ -7,10 +7,12 @@ public class Program { public static void Main() { + #region INCLUDE Console.WriteLine( MathEx.Max(7, 490)); Console.WriteLine( MathEx.Min("R.O.U.S.", "Fireswamp")); + #endregion INCLUDE } } } diff --git a/src/Chapter12/Listing12.37.InferringTheTypeParameter.cs b/src/Chapter12/Listing12.37.InferringTheTypeParameter.cs index 0f78b77f7..c784127c9 100644 --- a/src/Chapter12/Listing12.37.InferringTheTypeParameter.cs +++ b/src/Chapter12/Listing12.37.InferringTheTypeParameter.cs @@ -7,10 +7,12 @@ public class Program { public static void Main() { + #region INCLUDE Console.WriteLine( MathEx.Max(7, 490)); // No type arguments! Console.WriteLine( MathEx.Min("R.O.U.S'", "Fireswamp")); + #endregion INCLUDE } } } diff --git a/src/Chapter12/Listing12.38.SpecifyingConstraintsOnGenericMethods.cs b/src/Chapter12/Listing12.38.SpecifyingConstraintsOnGenericMethods.cs index 3bae65c6f..e0d33e03c 100644 --- a/src/Chapter12/Listing12.38.SpecifyingConstraintsOnGenericMethods.cs +++ b/src/Chapter12/Listing12.38.SpecifyingConstraintsOnGenericMethods.cs @@ -3,11 +3,14 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_38 using System; using Listing12_22; + #region INCLUDE public class ConsoleTreeControl { // Generic method Show public static void Show(BinaryTree tree, int indent) + #region HIGHLIGHT where T : IComparable + #endregion HIGHLIGHT { Console.WriteLine("\n{0}{1}", "+ --".PadLeft(5 * indent, ' '), @@ -18,4 +21,5 @@ public static void Show(BinaryTree tree, int indent) Show(tree.SubItems.Second, indent + 1); } } + #endregion INCLUDE } diff --git a/src/Chapter12/Listing12.39.BinaryTreeRequiringIComparableTypeParameters.cs b/src/Chapter12/Listing12.39.BinaryTreeRequiringIComparableTypeParameters.cs index b1d091a0a..e76c439da 100644 --- a/src/Chapter12/Listing12.39.BinaryTreeRequiringIComparableTypeParameters.cs +++ b/src/Chapter12/Listing12.39.BinaryTreeRequiringIComparableTypeParameters.cs @@ -1,8 +1,12 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_39 { + #region INCLUDE public class BinaryTree + #region HIGHLIGHT where T : System.IComparable + #endregion HIGHLIGHT { //... } + #endregion INCLUDE } diff --git a/src/Chapter12/Listing12.40.ConversionBetweenGenericsWithDifferentTypeParameters.cs b/src/Chapter12/Listing12.40.ConversionBetweenGenericsWithDifferentTypeParameters.cs index 38af2500e..359a21a7d 100644 --- a/src/Chapter12/Listing12.40.ConversionBetweenGenericsWithDifferentTypeParameters.cs +++ b/src/Chapter12/Listing12.40.ConversionBetweenGenericsWithDifferentTypeParameters.cs @@ -4,11 +4,12 @@ public class Program { public static void Main() { + #region INCLUDE // ... - // Error: Cannot convert type ... // Pair pair = (Pair)new Pair(); // IPair duple = (IPair)new Pair(); + #endregion INCLUDE } } } diff --git a/src/Chapter12/Listing12.41.PreventingCovarianceMaintainsHomogeneity.cs b/src/Chapter12/Listing12.41.PreventingCovarianceMaintainsHomogeneity.cs index e7f425521..1e751a3ea 100644 --- a/src/Chapter12/Listing12.41.PreventingCovarianceMaintainsHomogeneity.cs +++ b/src/Chapter12/Listing12.41.PreventingCovarianceMaintainsHomogeneity.cs @@ -7,16 +7,20 @@ public class Program { public static void Main() { + #region INCLUDE + // ... Contact contact1 = new Contact("Princess Buttercup"); Contact contact2 = new Contact("Inigo Montoya"); Pair contacts = new Pair(contact1, contact2); + #region HIGHLIGHT // This gives an error: Cannot convert type ... - // But suppose it did not // IPair pdaPair = (IPair) contacts; // This is perfectly legal, but not type-safe // pair.First = new Address("123 Sesame Street"); + #endregion HIGHLIGHT + #endregion INCLUDE } } } diff --git a/src/Chapter12/Listing12.42.PotentiallyPossibleCovariance.cs b/src/Chapter12/Listing12.42.PotentiallyPossibleCovariance.cs index 8af62509f..929042f2e 100644 --- a/src/Chapter12/Listing12.42.PotentiallyPossibleCovariance.cs +++ b/src/Chapter12/Listing12.42.PotentiallyPossibleCovariance.cs @@ -1,5 +1,6 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_42 { + #region INCLUDE interface IReadOnlyPair { T First { get; } @@ -14,7 +15,7 @@ interface IPair public struct Pair : IPair, IReadOnlyPair { - // ... + #region EXCLUDE #region Generated Interface Stub public T First { @@ -40,14 +41,16 @@ public T Second } } #endregion Generated Interface Stub + #endregion EXCLUDE } - class Program + public class Program { static void Main() { // Error: Only theoretically possible without // the out type parameter modifier + #region HIGHLIGHT //Pair contacts = // new Pair( // new Contact("Princess Buttercup"), @@ -55,6 +58,8 @@ static void Main() //IReadOnlyPair pair = contacts; //PdaItem pdaItem1 = pair.First; //PdaItem pdaItem2 = pair.Second; + #endregion HIGHLIGHT } } + #endregion INCLUDE } diff --git a/src/Chapter12/Listing12.43.CovarianceUsingTheOutTypeParameterModifier.cs b/src/Chapter12/Listing12.43.CovarianceUsingTheOutTypeParameterModifier.cs index 6981583e0..03ae3da02 100644 --- a/src/Chapter12/Listing12.43.CovarianceUsingTheOutTypeParameterModifier.cs +++ b/src/Chapter12/Listing12.43.CovarianceUsingTheOutTypeParameterModifier.cs @@ -3,11 +3,15 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_43 using Chapter08.Listing08_02; using Contact = Chapter12.Contact; + #region INCLUDE + #region HIGHLIGHT interface IReadOnlyPair + #endregion HIGHLIGHT { T First { get; } T Second { get; } } + #endregion INCLUDE interface IPair { diff --git a/src/Chapter12/Listing12.44.ContravarianceUsingTheInTypeParameterModifier.cs b/src/Chapter12/Listing12.44.ContravarianceUsingTheInTypeParameterModifier.cs index 357b6e9c6..024f0e77c 100644 --- a/src/Chapter12/Listing12.44.ContravarianceUsingTheInTypeParameterModifier.cs +++ b/src/Chapter12/Listing12.44.ContravarianceUsingTheInTypeParameterModifier.cs @@ -1,29 +1,30 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_44 { + #region INCLUDE class Fruit { } - class Apple : Fruit { } - class Orange : Fruit { } - + #region HIGHLIGHT interface ICompareThings { bool FirstIsBetter(T t1, T t2); } + #endregion HIGHLIGHT - class Program + public class Program { - class FruitComparer : ICompareThings + private class FruitComparer : ICompareThings { - // ... + #region EXCLUDE #region Generated Interface Stub public bool FirstIsBetter(Fruit t1, Fruit t2) { throw new System.NotImplementedException(); } #endregion Generated Interface Stub + #endregion EXCLUDE } static void Main() { @@ -50,4 +51,5 @@ static void Main() bool b3 = ac.FirstIsBetter(apple1, apple2); } } + #endregion INCLUDE } \ No newline at end of file diff --git a/src/Chapter12/Listing12.45.CompilerValidationOfVariance.cs b/src/Chapter12/Listing12.45.CompilerValidationOfVariance.cs index d571ec223..31923cf3b 100644 --- a/src/Chapter12/Listing12.45.CompilerValidationOfVariance.cs +++ b/src/Chapter12/Listing12.45.CompilerValidationOfVariance.cs @@ -2,19 +2,16 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_45 { - // // ERROR: Invalid variance: the type parameter 'T' is not - // // invariantly valid + #region INCLUDE + // ERROR: Invalid variance: the type parameter 'T' is not + // invariantly valid interface IPairInitializer { void Initialize(IPair pair); } - // Suppose the code above were legal, and see what goes // wrong: - - // ... - - class FruitPairInitializer : IPairInitializer + public class FruitPairInitializer : IPairInitializer { // Let’s initialize our pair of fruits with an // apple and an orange: @@ -27,18 +24,16 @@ public void Initialize(IPair pair) } // ... later ... - public class Program { public static void Main() { var f = new FruitPairInitializer(); - // This would be legal if contravariance were legal: IPairInitializer a = f; - // And now we write an orange into a pair of apples: a.Initialize(new Pair()); } } + #endregion INCLUDE } \ No newline at end of file diff --git a/src/Chapter12/Listing12.46.StackDeclaration.cs b/src/Chapter12/Listing12.46.StackDeclaration.cs index 6536cee67..58c461848 100644 --- a/src/Chapter12/Listing12.46.StackDeclaration.cs +++ b/src/Chapter12/Listing12.46.StackDeclaration.cs @@ -1,18 +1,17 @@ // Justification: Only showing partial implementaiton. #pragma warning disable CS8618 // Non-nullable field is uninitialized. Consider declaring as nullable. -#pragma warning disable IDE0051 // Remove unused private members -#pragma warning disable IDE0044 // Add readonly modifier namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_46 { using System; - + #region INCLUDE public class Stack where T : IComparable { private T[] _Items; - + // rest of the class here + #region EXCLUDE public T[] Items { get => _Items; set => _Items = value; } - - // ... + #endregion EXCLUDE } + #endregion INCLUDE } \ No newline at end of file diff --git a/src/Chapter12/Listing12.47.CILCodeForStack.cs b/src/Chapter12/Listing12.47.CILCodeForStack.cs index 11da038e0..099b99a85 100644 --- a/src/Chapter12/Listing12.47.CILCodeForStack.cs +++ b/src/Chapter12/Listing12.47.CILCodeForStack.cs @@ -1,11 +1,14 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_47 { // CIL CODE BELOW - - // .class private auto ansi beforefieldinit - // Stack'1<([mscorlib]System.IComparable)T> - // extends [mscorlib]System.Object - // { - // ... - // } + /* + #region INCLUDE + .class private auto ansi beforefieldinit + Stack'1<([mscorlib]System.IComparable)T> + extends [mscorlib]System.Object + { + ... + } + #endregion INCLUDE + */ } diff --git a/src/Chapter12/Listing12.48.CILWithExclamationPointNotation.cs b/src/Chapter12/Listing12.48.CILWithExclamationPointNotation.cs index b15aae8ee..5956f05a5 100644 --- a/src/Chapter12/Listing12.48.CILWithExclamationPointNotation.cs +++ b/src/Chapter12/Listing12.48.CILWithExclamationPointNotation.cs @@ -1,12 +1,15 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_48 { // CIL CODE BELOW - - // .class public auto ansi beforefieldinit - // 'Stack'1'<([mscorlib]System.IComparable) T> - // extends [mscorlib]System.Object - // { - // .field private !0[ ] items - // ... - // } + /* + #region INCLUDE + .class public auto ansi beforefieldinit + 'Stack'1'<([mscorlib]System.IComparable) T> + extends [mscorlib]System.Object + { + .field private !0[ ] items + ... + } + #endregion INCLUDE + */ } diff --git a/src/Chapter12/Listing12.49.StackIntDefinition.cs b/src/Chapter12/Listing12.49.StackIntDefinition.cs index 028b4337b..6350295b2 100644 --- a/src/Chapter12/Listing12.49.StackIntDefinition.cs +++ b/src/Chapter12/Listing12.49.StackIntDefinition.cs @@ -1,7 +1,6 @@ // Justification: Only showing partial implementaiton. #pragma warning disable CS0168 // Variable is declared but never used - using System.Collections.Generic; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_49 @@ -10,7 +9,9 @@ public class Program { static private void Main() { + #region INCLUDE Stack stack; + #endregion INCLUDE // ... } diff --git a/src/Chapter12/Listing12.50.DeclaringVariablesOfTypeStack.cs b/src/Chapter12/Listing12.50.DeclaringVariablesOfTypeStack.cs index a06cee092..9ccc2c3af 100644 --- a/src/Chapter12/Listing12.50.DeclaringVariablesOfTypeStack.cs +++ b/src/Chapter12/Listing12.50.DeclaringVariablesOfTypeStack.cs @@ -4,7 +4,9 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_50 { public class Program { + #region INCLUDE Stack stackOne = new Stack(); Stack stackTwo = new Stack(); + #endregion INCLUDE } } From 357dfe741947975dc231a9fb9a33fa89b15205e7 Mon Sep 17 00:00:00 2001 From: Benjamin Michaelis Date: Thu, 26 May 2022 17:15:19 -0700 Subject: [PATCH 06/11] Reviewed through 12.4 --- .../Listing12.02.SupportingUndoInEtchASketchGame.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Chapter12/Listing12.02.SupportingUndoInEtchASketchGame.cs b/src/Chapter12/Listing12.02.SupportingUndoInEtchASketchGame.cs index 42c13d678..f0e45bf13 100644 --- a/src/Chapter12/Listing12.02.SupportingUndoInEtchASketchGame.cs +++ b/src/Chapter12/Listing12.02.SupportingUndoInEtchASketchGame.cs @@ -15,11 +15,9 @@ public static void Main() public static void Sketch() { - Stack path = new Stack(); Cell currentPosition; ConsoleKeyInfo key; // Added in C# 2.0 - #region EXCLUDE Console.WriteLine("Use arrow keys to draw. X to exit."); for(int i = 2; i < Console.WindowHeight; i++) @@ -49,7 +47,9 @@ public static void Sketch() #endregion HIGHLIGHT Console.SetCursorPosition( currentPosition.X, currentPosition.Y); + #region EXCLUDE FillCell(currentPosition, ConsoleColor.Black); + #endregion EXCLUDE Undo(); } break; @@ -96,7 +96,9 @@ public static void Sketch() #region HIGHLIGHT path.Push(currentPosition); #endregion HIGHLIGHT + #region EXCLUDE FillCell(currentPosition); + #endregion EXCLUDE break; default: From 315f59e1c5d19f161b1f0c7a7cee4e0a7b71c29d Mon Sep 17 00:00:00 2001 From: Hanna Michaelis Date: Wed, 15 Jun 2022 10:50:01 -0700 Subject: [PATCH 07/11] Changes from pdf review --- .../Listing12.03.DefiningASpecializedStackClass.cs | 4 ++-- ....ConversionBetweenGenericsWithDifferentTypeParameters.cs | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Chapter12/Listing12.03.DefiningASpecializedStackClass.cs b/src/Chapter12/Listing12.03.DefiningASpecializedStackClass.cs index ff080fd2d..001b7e086 100644 --- a/src/Chapter12/Listing12.03.DefiningASpecializedStackClass.cs +++ b/src/Chapter12/Listing12.03.DefiningASpecializedStackClass.cs @@ -4,8 +4,8 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_03 #region INCLUDE public class CellStack { - public virtual object Pop() { return new Cell(); } // would return that last cell added and remove it from the list - public virtual void Push(Cell obj) { } + public virtual Cell Pop() { return new Cell(); } // would return that last cell added and remove it from the list + public virtual void Push(Cell cell) { } // ... } #endregion INCLUDE diff --git a/src/Chapter12/Listing12.40.ConversionBetweenGenericsWithDifferentTypeParameters.cs b/src/Chapter12/Listing12.40.ConversionBetweenGenericsWithDifferentTypeParameters.cs index 359a21a7d..ac0130af7 100644 --- a/src/Chapter12/Listing12.40.ConversionBetweenGenericsWithDifferentTypeParameters.cs +++ b/src/Chapter12/Listing12.40.ConversionBetweenGenericsWithDifferentTypeParameters.cs @@ -4,12 +4,14 @@ public class Program { public static void Main() { + /* #region INCLUDE // ... // Error: Cannot convert type ... - // Pair pair = (Pair)new Pair(); - // IPair duple = (IPair)new Pair(); + Pair pair = (Pair)new Pair(); + IPair duple = (IPair)new Pair(); #endregion INCLUDE + */ } } } From e5a6af4c76ca1a35ad915a26a6a110e658a1339a Mon Sep 17 00:00:00 2001 From: Hanna Michaelis Date: Wed, 15 Jun 2022 11:04:26 -0700 Subject: [PATCH 08/11] Changes from pdf review --- ...aringSystemValueTupleInstantiationApproaches.cs | 14 +++++++++----- src/Chapter12/Listing12.18.NestedGenericTypes.cs | 4 ++-- ....NeedingTheTypeParameterToSupportAnInterface.cs | 2 ++ ...onBetweenGenericsWithDifferentTypeParameters.cs | 4 ++-- ...ontravarianceUsingTheInTypeParameterModifier.cs | 5 +---- .../Listing12.45.CompilerValidationOfVariance.cs | 7 +++++-- ...Listing12.48.CILWithExclamationPointNotation.cs | 2 ++ 7 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/Chapter12/Listing12.17.ComparingSystemValueTupleInstantiationApproaches.cs b/src/Chapter12/Listing12.17.ComparingSystemValueTupleInstantiationApproaches.cs index 35fc3f002..350d6f31c 100644 --- a/src/Chapter12/Listing12.17.ComparingSystemValueTupleInstantiationApproaches.cs +++ b/src/Chapter12/Listing12.17.ComparingSystemValueTupleInstantiationApproaches.cs @@ -13,16 +13,20 @@ public static void Main() (string, Contact) keyValuePair; keyValuePair = ("555-55-5555", new Contact("Inigo Montoya")); - #elif CSHARP6 +#else // Use System.ValueTupe prior to C# 7.0 ValueTuple keyValuePair; keyValuePair = - new ValueTuple( + #region HIGHLIGHT + ValueTuple.Create( + #endregion HIGHLIGHT "555-55-5555", new Contact("Inigo Montoya")); keyValuePair = - ValueTuple.Create( + #region HIGHLIGHT + new ValueTuple( + #endregion HIGHLIGHT "555-55-5555", new Contact("Inigo Montoya")); - #endif // !PRECSHARP7 - #endregion INCLUDE +#endif // !PRECSHARP7 + #endregion INCLUDE } } } diff --git a/src/Chapter12/Listing12.18.NestedGenericTypes.cs b/src/Chapter12/Listing12.18.NestedGenericTypes.cs index 3c0a50ce6..44254d777 100644 --- a/src/Chapter12/Listing12.18.NestedGenericTypes.cs +++ b/src/Chapter12/Listing12.18.NestedGenericTypes.cs @@ -3,12 +3,12 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_18 #pragma warning disable 0693 // Disabled warning due to nested type parameter // with overlapping name #region INCLUDE - class Container + public class Container { // Nested classes inherit type parameter // Reusing a type parameter name will cause // a warning - class Nested + public class Nested { #region HIGHLIGHT static void Method(T param0, U param1) diff --git a/src/Chapter12/Listing12.20.NeedingTheTypeParameterToSupportAnInterface.cs b/src/Chapter12/Listing12.20.NeedingTheTypeParameterToSupportAnInterface.cs index 65c3e1fc6..2c02da01c 100644 --- a/src/Chapter12/Listing12.20.NeedingTheTypeParameterToSupportAnInterface.cs +++ b/src/Chapter12/Listing12.20.NeedingTheTypeParameterToSupportAnInterface.cs @@ -19,6 +19,7 @@ public Pair> SubItems set { #region INCLUDE + #region HIGHLIGHT IComparable first; // ERROR: Cannot implicitly convert type... //first = value.First; // Explicit cast required @@ -35,6 +36,7 @@ public Pair> SubItems // //... //} _SubItems = value; + #endregion HIGHLIGHT #endregion INCLUDE } } diff --git a/src/Chapter12/Listing12.40.ConversionBetweenGenericsWithDifferentTypeParameters.cs b/src/Chapter12/Listing12.40.ConversionBetweenGenericsWithDifferentTypeParameters.cs index ac0130af7..3edb6e9bf 100644 --- a/src/Chapter12/Listing12.40.ConversionBetweenGenericsWithDifferentTypeParameters.cs +++ b/src/Chapter12/Listing12.40.ConversionBetweenGenericsWithDifferentTypeParameters.cs @@ -8,8 +8,8 @@ public static void Main() #region INCLUDE // ... // Error: Cannot convert type ... - Pair pair = (Pair)new Pair(); - IPair duple = (IPair)new Pair(); + Pair pair = (Pair)new Pair(); + IPair duple = (IPair)new Pair(); #endregion INCLUDE */ } diff --git a/src/Chapter12/Listing12.44.ContravarianceUsingTheInTypeParameterModifier.cs b/src/Chapter12/Listing12.44.ContravarianceUsingTheInTypeParameterModifier.cs index 024f0e77c..10124ffaf 100644 --- a/src/Chapter12/Listing12.44.ContravarianceUsingTheInTypeParameterModifier.cs +++ b/src/Chapter12/Listing12.44.ContravarianceUsingTheInTypeParameterModifier.cs @@ -28,7 +28,7 @@ public bool FirstIsBetter(Fruit t1, Fruit t2) } static void Main() { - // Allowed in C# 4.0 + // Allowed in C# 4.0 and later ICompareThings fc = new FruitComparer(); Apple apple1 = new Apple(); @@ -37,17 +37,14 @@ static void Main() Orange orange = new Orange(); // A fruit comparer can compare apples and oranges: - bool b1 = fc.FirstIsBetter(apple1, orange); // or apples and apples: - bool b2 = fc.FirstIsBetter(apple1, apple2); // This is legal because the interface is // contravariant. ICompareThings ac = fc; // This is really a fruit comparer, so it can // still compare two apples - bool b3 = ac.FirstIsBetter(apple1, apple2); } } diff --git a/src/Chapter12/Listing12.45.CompilerValidationOfVariance.cs b/src/Chapter12/Listing12.45.CompilerValidationOfVariance.cs index 31923cf3b..68248f088 100644 --- a/src/Chapter12/Listing12.45.CompilerValidationOfVariance.cs +++ b/src/Chapter12/Listing12.45.CompilerValidationOfVariance.cs @@ -15,7 +15,6 @@ public class FruitPairInitializer : IPairInitializer { // Let’s initialize our pair of fruits with an // apple and an orange: - public void Initialize(IPair pair) { pair.First = new Orange(); @@ -24,16 +23,20 @@ public void Initialize(IPair pair) } // ... later ... + #region EXCLUDE public class Program { public static void Main() { + #endregion EXCLUDE var f = new FruitPairInitializer(); // This would be legal if contravariance were legal: IPairInitializer a = f; // And now we write an orange into a pair of apples: a.Initialize(new Pair()); + #region EXCLUDE } } #endregion INCLUDE -} \ No newline at end of file +} +#endregion EXCLUDE \ No newline at end of file diff --git a/src/Chapter12/Listing12.48.CILWithExclamationPointNotation.cs b/src/Chapter12/Listing12.48.CILWithExclamationPointNotation.cs index 5956f05a5..85cf064b9 100644 --- a/src/Chapter12/Listing12.48.CILWithExclamationPointNotation.cs +++ b/src/Chapter12/Listing12.48.CILWithExclamationPointNotation.cs @@ -7,7 +7,9 @@ .class public auto ansi beforefieldinit 'Stack'1'<([mscorlib]System.IComparable) T> extends [mscorlib]System.Object { + #region HIGHLIGHT .field private !0[ ] items + #endregion HIGHLIGHT ... } #endregion INCLUDE From f0a395eb6bf881b9a192515bd9df1b76f255229c Mon Sep 17 00:00:00 2001 From: Hanna Michaelis Date: Wed, 15 Jun 2022 11:07:40 -0700 Subject: [PATCH 09/11] More changes from pdf review --- ...ComparingSystemValueTupleInstantiationApproaches.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Chapter12/Listing12.17.ComparingSystemValueTupleInstantiationApproaches.cs b/src/Chapter12/Listing12.17.ComparingSystemValueTupleInstantiationApproaches.cs index 350d6f31c..a6a4c0804 100644 --- a/src/Chapter12/Listing12.17.ComparingSystemValueTupleInstantiationApproaches.cs +++ b/src/Chapter12/Listing12.17.ComparingSystemValueTupleInstantiationApproaches.cs @@ -8,12 +8,12 @@ public class Program { public static void Main() { - #region INCLUDE - #if !PRECSHARP7 + #region INCLUDE + #if !PRECSHARP7 (string, Contact) keyValuePair; keyValuePair = ("555-55-5555", new Contact("Inigo Montoya")); -#else // Use System.ValueTupe prior to C# 7.0 + #else // Use System.ValueTupe prior to C# 7.0 ValueTuple keyValuePair; keyValuePair = #region HIGHLIGHT @@ -22,10 +22,10 @@ public static void Main() "555-55-5555", new Contact("Inigo Montoya")); keyValuePair = #region HIGHLIGHT - new ValueTuple( + new ValueTuple( #endregion HIGHLIGHT "555-55-5555", new Contact("Inigo Montoya")); -#endif // !PRECSHARP7 + #endif // !PRECSHARP7 #endregion INCLUDE } } From 43e6cbfc4018ca357f91b299e36705763832b0b8 Mon Sep 17 00:00:00 2001 From: Hanna Michaelis Date: Wed, 15 Jun 2022 11:09:51 -0700 Subject: [PATCH 10/11] Minor changes from pdf review --- src/Chapter12/Listing12.45.CompilerValidationOfVariance.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Chapter12/Listing12.45.CompilerValidationOfVariance.cs b/src/Chapter12/Listing12.45.CompilerValidationOfVariance.cs index 68248f088..cb3a27933 100644 --- a/src/Chapter12/Listing12.45.CompilerValidationOfVariance.cs +++ b/src/Chapter12/Listing12.45.CompilerValidationOfVariance.cs @@ -37,6 +37,6 @@ public static void Main() #region EXCLUDE } } + #endregion EXCLUDE #endregion INCLUDE -} -#endregion EXCLUDE \ No newline at end of file +} \ No newline at end of file From c5d9dc797e890bb6549be2b3d27d50ad42ce5d78 Mon Sep 17 00:00:00 2001 From: Hanna Michaelis Date: Wed, 15 Jun 2022 11:18:15 -0700 Subject: [PATCH 11/11] Changes to 12.20, 12.44 and 12.48 --- .../Listing12.20.NeedingTheTypeParameterToSupportAnInterface.cs | 2 -- ...isting12.44.ContravarianceUsingTheInTypeParameterModifier.cs | 1 - src/Chapter12/Listing12.48.CILWithExclamationPointNotation.cs | 2 +- 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Chapter12/Listing12.20.NeedingTheTypeParameterToSupportAnInterface.cs b/src/Chapter12/Listing12.20.NeedingTheTypeParameterToSupportAnInterface.cs index 2c02da01c..9735d9b28 100644 --- a/src/Chapter12/Listing12.20.NeedingTheTypeParameterToSupportAnInterface.cs +++ b/src/Chapter12/Listing12.20.NeedingTheTypeParameterToSupportAnInterface.cs @@ -18,7 +18,6 @@ public Pair> SubItems get { return _SubItems; } set { - #region INCLUDE #region HIGHLIGHT IComparable first; // ERROR: Cannot implicitly convert type... @@ -37,7 +36,6 @@ public Pair> SubItems //} _SubItems = value; #endregion HIGHLIGHT - #endregion INCLUDE } } private Pair> _SubItems; diff --git a/src/Chapter12/Listing12.44.ContravarianceUsingTheInTypeParameterModifier.cs b/src/Chapter12/Listing12.44.ContravarianceUsingTheInTypeParameterModifier.cs index 10124ffaf..bf431332d 100644 --- a/src/Chapter12/Listing12.44.ContravarianceUsingTheInTypeParameterModifier.cs +++ b/src/Chapter12/Listing12.44.ContravarianceUsingTheInTypeParameterModifier.cs @@ -32,7 +32,6 @@ static void Main() ICompareThings fc = new FruitComparer(); Apple apple1 = new Apple(); - Apple apple2 = new Apple(); Orange orange = new Orange(); diff --git a/src/Chapter12/Listing12.48.CILWithExclamationPointNotation.cs b/src/Chapter12/Listing12.48.CILWithExclamationPointNotation.cs index 85cf064b9..efdbb6916 100644 --- a/src/Chapter12/Listing12.48.CILWithExclamationPointNotation.cs +++ b/src/Chapter12/Listing12.48.CILWithExclamationPointNotation.cs @@ -8,7 +8,7 @@ .class public auto ansi beforefieldinit extends [mscorlib]System.Object { #region HIGHLIGHT - .field private !0[ ] items + .field private !0[ ] _Items #endregion HIGHLIGHT ... }