Regions through 12.13
MODIFY
src/Chapter12/Listing12.07.DeclaringAGenericClassStack.cs
src/Chapter12/Listing12.07.DeclaringAGenericClassStack.cs
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_07
{
+ #region INCLUDE
public class Stack<T>
{
public Stack(int maxSize)
@@ -17,8 +18,10 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_07
public T Pop()
{
- //...
+ #region EXCLUDE
return InternalItems[0]; //just for the example
+ #endregion EXCLUDE
}
}
+ #endregion INCLUDE
}

MODIFY
src/Chapter12/Listing12.08.DeclaringAGenericInterface.cs
src/Chapter12/Listing12.08.DeclaringAGenericInterface.cs
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_08
{
+ #region INCLUDE
interface IPair<T>
{
T First { get; set; }
T Second { get; set; }
}
+ #endregion INCLUDE
}

MODIFY
src/Chapter12/Listing12.09.ImplementingAGenericInterface.cs
src/Chapter12/Listing12.09.ImplementingAGenericInterface.cs
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_09
{
using Listing12_08;
-
+ #region INCLUDE
public struct Pair<T> : IPair<T>
{
public T First { get; set; }
public T Second { get; set; }
}
-
+ #endregion INCLUDE
}

MODIFY
src/Chapter12/Listing12.10.DuplicatingAnInterfaceImplementationOnASingleClass.cs
src/Chapter12/Listing12.10.DuplicatingAnInterfaceImplementationOnASingleClass.cs
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_10
{
using System.Collections.Generic;
-
+ #region INCLUDE
public interface IContainer<T>
{
- ICollection<T> Items
- {
- get;
- set;
- }
+ ICollection<T> Items { get; set; }
}
public class Person : IContainer<Address>,
IContainer<Phone>, IContainer<Email>
{
+ #region HIGHLIGHT
ICollection<Address> IContainer<Address>.Items
+ #endregion HIGHLIGHT
{
get
{
- //...
+ #region EXCLUDE
return new List<Address>();
+ #endregion EXCLUDE
}
set
{
//...
}
}
+ #region HIGHLIGHT
ICollection<Phone> IContainer<Phone>.Items
+ #endregion HIGHLIGHT
{
get
{
- //...
+ #region EXCLUDE
return new List<Phone>();
+ #endregion EXCLUDE
}
set
{
//...
}
}
+ #region HIGHLIGHT
ICollection<Email> IContainer<Email>.Items
+ #endregion HIGHLIGHT
{
get
{
- //...
+ #region EXCLUDE
return new List<Email>();
+ #endregion EXCLUDE
}
set
{
@@ -51,6 +56,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_10
}
}
}
+ #endregion INCLUDE
public class Address { } // For example purposes only
public class Phone { } // For example purposes only

MODIFY
src/Chapter12/Listing12.11.DeclaringAGenericTypeConstructor.cs
src/Chapter12/Listing12.11.DeclaringAGenericTypeConstructor.cs
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_11
{
using Listing12_08;
-
+ #region INCLUDE
public struct Pair<T> : IPair<T>
{
+ #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
}

MODIFY
src/Chapter12/Listing12.12.NotInitializingAllFieldsCasuingACompileError.cs
src/Chapter12/Listing12.12.NotInitializingAllFieldsCasuingACompileError.cs
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_12
{
using Listing12_08;
-
+ #region INCLUDE
public struct Pair<T> : IPair<T>
{
// ERROR: Field 'Pair<T>.Second' must be fully assigned
@@ -11,6 +11,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_12
// First = first;
// }
+ #region EXCLUDE
public Pair(T first, T second)
{
First = first;
@@ -19,6 +20,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_12
public T First { get; set; }
public T Second { get; set; }
-
+ #endregion EXCLUDE
}
+ #endregion INCLUDE
}

MODIFY
src/Chapter12/Listing12.13.InitializingAFieldWithTheDefaultOperator.cs
src/Chapter12/Listing12.13.InitializingAFieldWithTheDefaultOperator.cs
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_13
{
using Listing12_08;
-
+ #region INCLUDE
public struct Pair<T> : IPair<T>
{
public Pair(T first)
{
First = first;
+ #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;
+ #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 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_13
public T First { get; set; }
public T Second { get; set; }
+ #endregion EXCLUDE
}
+ #endregion INCLUDE
}

Regions through 12.13