Chapter 12 Regions through 12.6
MODIFY
src/Chapter12/Listing12.01.TheSystemCollectionsStackMethodSignatures.cs
src/Chapter12/Listing12.01.TheSystemCollectionsStackMethodSignatures.cs
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
}

MODIFY
src/Chapter12/Listing12.02.SupportingUndoInEtchASketchGame.cs
src/Chapter12/Listing12.02.SupportingUndoInEtchASketchGame.cs
-// 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 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_02
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 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_02
currentPosition = new Cell(Console.WindowWidth / 2, Console.WindowHeight / 2);
path.Push(currentPosition);
FillCell(currentPosition);
+ #endregion EXCLUDE
do
{
@@ -40,7 +44,9 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_02
// 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,6 +54,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_02
}
break;
case ConsoleKey.DownArrow:
+ #region EXCLUDE
if (Console.CursorTop < Console.WindowHeight - 2)
{
currentPosition = new Cell(
@@ -56,7 +63,9 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_02
path.Push(currentPosition);
FillCell(currentPosition);
break;
+ #endregion EXCLUDE
case ConsoleKey.UpArrow:
+ #region EXCLUDE
if (Console.CursorTop > 1)
{
currentPosition = new Cell(
@@ -65,7 +74,9 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_02
path.Push(currentPosition);
FillCell(currentPosition);
break;
+ #endregion EXCLUDE
case ConsoleKey.LeftArrow:
+ #region EXCLUDE
if (Console.CursorLeft > 1)
{
currentPosition = new Cell(
@@ -74,6 +85,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_02
path.Push(currentPosition);
FillCell(currentPosition);
break;
+ #endregion EXCLUDE
case ConsoleKey.RightArrow:
// SaveState()
if(Console.CursorLeft < Console.WindowWidth - 2)
@@ -81,7 +93,9 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_02
currentPosition = new Cell(
Console.CursorLeft + 1, Console.CursorTop);
}
+ #region HIGHLIGHT
path.Push(currentPosition);
+ #endregion HIGHLIGHT
FillCell(currentPosition);
break;
@@ -89,11 +103,10 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_02
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 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_02
Console.SetCursorPosition(cell.X, cell.Y);
Console.BackgroundColor = ConsoleColor.Black;
}
+ #endregion EXCLUDE
}
public struct Cell
@@ -131,4 +145,5 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_02
Y = y;
}
}
+ #endregion INCLUDE
}

MODIFY
src/Chapter12/Listing12.03.DefiningASpecializedStackClass.cs
src/Chapter12/Listing12.03.DefiningASpecializedStackClass.cs
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
}

MODIFY
src/Chapter12/Listing12.04.DeclaringVersionsOfVariousValueTypesThatStoreNull.cs
src/Chapter12/Listing12.04.DeclaringVersionsOfVariousValueTypesThatStoreNull.cs
@@ -2,6 +2,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_04
{
using System;
+ #region INCLUDE
struct NullableInt
{
/// <summary>
@@ -35,4 +36,5 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_04
}
// ...
+ #endregion INCLUDE
}

MODIFY
src/Chapter12/Listing12.05.DeclaringANullableTypeThatContainsAValuePropertyOfTypeObject.cs
src/Chapter12/Listing12.05.DeclaringANullableTypeThatContainsAValuePropertyOfTypeObject.cs
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_05
{
+ #region INCLUDE
struct Nullable
{
/// <summary>
@@ -15,4 +16,5 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_05
// ...
}
+ #endregion INCLUDE
}

MODIFY
src/Chapter12/Listing12.06.ImplementingUndoWithAGenericStackClass.cs
src/Chapter12/Listing12.06.ImplementingUndoWithAGenericStackClass.cs
-// 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<Cell> path = new Stack<Cell>();
+ #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 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_06
currentPosition = new Cell(Console.WindowWidth / 2, Console.WindowHeight / 2);
path.Push(currentPosition);
FillCell(currentPosition);
+ #endregion EXCLUDE
do
{
@@ -39,8 +44,10 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_06
// 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,6 +55,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_06
}
break;
case ConsoleKey.DownArrow:
+ #region EXCLUDE
if (Console.CursorTop < Console.WindowHeight - 2)
{
currentPosition = new Cell(
@@ -57,7 +65,9 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_06
path.Push(currentPosition);
FillCell(currentPosition);
break;
+ #endregion EXCLUDE
case ConsoleKey.UpArrow:
+ #region EXCLUDE
if (Console.CursorTop > 1)
{
currentPosition = new Cell(
@@ -67,7 +77,9 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_06
path.Push(currentPosition);
FillCell(currentPosition);
break;
+ #endregion EXCLUDE
case ConsoleKey.LeftArrow:
+ #region EXCLUDE
if (Console.CursorLeft > 1)
{
currentPosition = new Cell(
@@ -77,6 +89,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_06
path.Push(currentPosition);
FillCell(currentPosition);
break;
+ #endregion EXCLUDE
case ConsoleKey.RightArrow:
// SaveState()
if(Console.CursorLeft < Console.WindowWidth - 2)
@@ -84,8 +97,10 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_06
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 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_06
}
while(key.Key != ConsoleKey.X); // Use X to quit
}
-
+ #region EXCLUDE
private static ConsoleKeyInfo Move()
{
return Console.ReadKey(true);
@@ -121,8 +136,9 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_06
Console.SetCursorPosition(cell.X, cell.Y);
Console.BackgroundColor = ConsoleColor.Black;
}
+ #endregion EXCLUDE
}
-
+ #endregion INCLUDE
public struct Cell
{
readonly public int X;

Chapter 12 Regions through 12.6