Regions through Chapter 12.23
MODIFY
src/Chapter12/Listing12.14.DeclaringAGenericWithMultipleTypeParameters.cs
src/Chapter12/Listing12.14.DeclaringAGenericWithMultipleTypeParameters.cs
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_14
{
+ #region INCLUDE
interface IPair<TFirst, TSecond>
{
TFirst First { get; set; }
@@ -16,6 +17,6 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_14
public TFirst First { get; set; }
public TSecond Second { get; set; }
-
}
+ #endregion INCLUDE
}

MODIFY
src/Chapter12/Listing12.15.UsingATypewithMultipleTypeParameters.cs
src/Chapter12/Listing12.15.UsingATypewithMultipleTypeParameters.cs
@@ -7,12 +7,14 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_15
{
public static void Main()
{
+ #region INCLUDE
Pair<int, string> historicalEvent =
new Pair<int, string>(1914,
"Shackleton leaves for South Pole on ship Endurance");
Console.WriteLine("{0}: {1}",
historicalEvent.First, historicalEvent.Second);
+ #endregion INCLUDE
}
}
}

MODIFY
src/Chapter12/Listing12.16.UsingArityToOverloadATypeDefinition.cs
src/Chapter12/Listing12.16.UsingArityToOverloadATypeDefinition.cs
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_16
{
+ #region INCLUDE
public class Tuple
{
// ...
@@ -36,4 +37,5 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_16
{
// ...
}
+ #endregion INCLUDE
}

MODIFY
src/Chapter12/Listing12.17.ComparingSystemValueTupleInstantiationApproaches.cs
src/Chapter12/Listing12.17.ComparingSystemValueTupleInstantiationApproaches.cs
@@ -8,6 +8,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_17
{
public static void Main()
{
+ #region INCLUDE
#if !PRECSHARP7
(string, Contact) keyValuePair;
keyValuePair =
@@ -21,6 +22,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_17
ValueTuple.Create(
"555-55-5555", new Contact("Inigo Montoya"));
#endif // !PRECSHARP7
+ #endregion INCLUDE
}
}
}

MODIFY
src/Chapter12/Listing12.18.NestedGenericTypes.cs
src/Chapter12/Listing12.18.NestedGenericTypes.cs
@@ -2,6 +2,7 @@ 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<T, U>
{
// Nested classes inherit type parameter
@@ -9,10 +10,12 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_18
// a warning
class Nested<U>
{
- // TODO: Update listing in Manuscript
+ #region HIGHLIGHT
static void Method(T param0, U param1)
+ #endregion HIGHLIGHT
{
}
}
}
+ #endregion INCLUDE
}

MODIFY
src/Chapter12/Listing12.19.DeclaringABinaryTreeClassWithNoConstraints.cs
src/Chapter12/Listing12.19.DeclaringABinaryTreeClassWithNoConstraints.cs
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_19
{
using Listing12_13;
-
+ #region INCLUDE
public class BinaryTree<T>
{
public BinaryTree(T item)
@@ -12,4 +12,5 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_19
public T Item { get; set; }
public Pair<BinaryTree<T>> SubItems { get; set; }
}
+ #endregion INCLUDE
}

MODIFY
src/Chapter12/Listing12.20.NeedingTheTypeParameterToSupportAnInterface.cs
src/Chapter12/Listing12.20.NeedingTheTypeParameterToSupportAnInterface.cs
@@ -4,7 +4,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_20
using Listing12_13;
// In an actual implementation Item would be used to hold some value
#pragma warning disable CS0168
-
+ #region INCLUDE
public class BinaryTree<T>
{
public BinaryTree(T item)
@@ -13,12 +13,12 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_20
}
public T Item { get; set; }
-
public Pair<BinaryTree<T>> SubItems
{
get { return _SubItems; }
set
{
+ #region INCLUDE
IComparable<T> first;
// ERROR: Cannot implicitly convert type...
//first = value.First; // Explicit cast required
@@ -35,9 +35,11 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_20
// //...
//}
_SubItems = value;
+ #endregion INCLUDE
}
}
private Pair<BinaryTree<T>> _SubItems;
}
+ #endregion INCLUDE
#pragma warning restore CS0168
}

MODIFY
src/Chapter12/Listing12.21.NeedingTheTypeParameterToSupportAnInterfaceOrExceptionThrown.cs
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<T>
{
public BinaryTree(T item)
@@ -18,16 +18,27 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_21
{
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 {
+ #endregion EXCLUDE
+ case
+ {
+ #region HIGHLIGHT
First: {Item: IComparable<T> first },
+ #endregion HIGHLIGHT
Second: {Item: T second } }:
+ #region HIGHLIGHT
if (first.CompareTo(second) < 0)
+ #endregion HIGHLIGHT
{
// first is less than second
}
@@ -46,4 +57,5 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_21
}
private Pair<BinaryTree<T>?>? _SubItems;
}
+ #endregion INCLUDE
}

MODIFY
src/Chapter12/Listing12.22.DeclaringAnInterfaceConstraint.cs
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<T>
+ #region HIGHLIGHT
where T : System.IComparable<T>
+ #endregion HIGHLIGHT
{
public BinaryTree(T item)
{
@@ -12,26 +15,35 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_22
}
public T Item { get; set; }
-
- public Pair<BinaryTree<T>> SubItems
+ public Pair<BinaryTree<T>?>? 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 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_22
_SubItems = value;
}
}
- private Pair<BinaryTree<T>> _SubItems;
-
+ private Pair<BinaryTree<T>?>? _SubItems;
}
+ #endregion INCLUDE
}

MODIFY
src/Chapter12/Listing12.23.DeclaringABaseClassConstraint.cs
src/Chapter12/Listing12.23.DeclaringABaseClassConstraint.cs
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_23
{
+ #region INCLUDE
public class EntityDictionary<TKey, TValue>
: System.Collections.Generic.Dictionary<TKey, TValue>
+ #region HIGHLIGHT
where TKey : notnull
where TValue : EntityBase
+ #endregion HIGHLIGHT
{
// ...
}
-
+ #endregion INCLUDE
public class EntityBase
{
}

Regions through Chapter 12.23