Add Regions to chapter 8
MODIFY
src/Chapter08.Tests/Listing08.10.InterfaceExtensionMethods.Tests.cs
src/Chapter08.Tests/Listing08.10.InterfaceExtensionMethods.Tests.cs
@@ -15,7 +15,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter08.Listing08_10.Tests
Dick Traci 123-123-1234123 Main St., Spokane, WA 99037
Title Author Year
-Celebration of Discipline Richard Foster 1978
+The End of Poverty: Economic Possibilities for Our Time Jeffrey Sachs 2006
Orthodoxy G.K. Chesterton 1908
The Hitchhiker's Guide to the Galaxy Douglas Adams 1979
";

MODIFY
src/Chapter08/Listing08.02.ImplementingAndUsingInterfaces.cs
src/Chapter08/Listing08.02.ImplementingAndUsingInterfaces.cs
{
using System;
- public class Program
- {
- public static void Main()
- {
- Contact[] contacts = new Contact[]
- {
- new Contact(
- "Dick", "Traci",
- "123 Main St., Spokane, WA 99037",
- "123-123-1234"),
- new Contact(
- "Andrew", "Littman",
- "1417 Palmary St., Dallas, TX 55555",
- "555-123-4567"),
- new Contact(
- "Mary", "Hartfelt",
- "1520 Thunder Way, Elizabethton, PA 44444",
- "444-123-4567"),
- new Contact(
- "John", "Lindherst",
- "1 Aerial Way Dr., Monteray, NH 88888",
- "222-987-6543"),
- new Contact(
- "Pat", "Wilson",
- "565 Irving Dr., Parksdale, FL 22222",
- "123-456-7890"),
- new Contact(
- "Jane", "Doe",
- "123 Main St., Aurora, IL 66666",
- "333-345-6789")
- };
-
- // Classes are cast implicitly convertible to
- // their supported interfaces
- ConsoleListControl.List(Contact.Headers, contacts);
-
- Console.WriteLine();
-
- Publication[] publications = new Publication[3] {
- new Publication(
- "The End of Poverty: Economic Possibilities for Our Time",
- "Jeffrey Sachs", 2006),
- new Publication("Orthodoxy",
- "G.K. Chesterton", 1908),
- new Publication(
- "The Hitchhiker's Guide to the Galaxy",
- "Douglas Adams", 1979)
- };
- ConsoleListControl.List(
- Publication.Headers, publications);
- }
- }
-
+ #region INCLUDE
public interface IListable
{
// Return the value of each cell in the row
- string?[] CellValues
- {
- get;
- }
+ #region HIGHLIGHT
+ string?[] CellValues { get; }
+ #endregion
}
public abstract class PdaItem
public virtual string Name { get; set; }
}
+ #region HIGHLIGHT
public class Contact : PdaItem, IListable
+ #endregion
{
public Contact(string firstName, string lastName,
string address, string phone)
public string LastName { get; }
public string Address { get; }
public string Phone { get; }
+ static public string GetName(string firstName, string lastName)
+ => $"{ firstName } { lastName }";
+ #region HIGHLIGHT
public string[] CellValues
{
get
};
}
}
+ #endregion
public static string[] Headers
{
"Address " };
}
}
-
- static public string GetName(string firstName, string lastName)
- => $"{ firstName } { lastName }";
+ // ...
}
+ #region HIGHLIGHT
public class Publication : IListable
+ #endregion
{
public Publication(string title, string author, int year)
{
public string Author { get; }
public int Year { get; }
+ #region HIGHLIGHT
public string?[] CellValues
{
get
};
}
}
+ #endregion
public static string[] Headers
{
// ...
}
+ public class Program
+ {
+ public static void Main()
+ {
+ Contact[] contacts = new Contact[]
+ {
+ new Contact(
+ "Dick", "Traci",
+ "123 Main St., Spokane, WA 99037",
+ "123-123-1234"),
+ new Contact(
+ "Andrew", "Littman",
+ "1417 Palmary St., Dallas, TX 55555",
+ "555-123-4567"),
+ new Contact(
+ "Mary", "Hartfelt",
+ "1520 Thunder Way, Elizabethton, PA 44444",
+ "444-123-4567"),
+ new Contact(
+ "John", "Lindherst",
+ "1 Aerial Way Dr., Monteray, NH 88888",
+ "222-987-6543"),
+ new Contact(
+ "Pat", "Wilson",
+ "565 Irving Dr., Parksdale, FL 22222",
+ "123-456-7890"),
+ new Contact(
+ "Jane", "Doe",
+ "123 Main St., Aurora, IL 66666",
+ "333-345-6789")
+ };
+
+ // Classes are cast implicitly convertible to
+ // their supported interfaces
+ ConsoleListControl.List(Contact.Headers, contacts);
+
+ Console.WriteLine();
+
+ Publication[] publications = new Publication[3] {
+ new Publication(
+ "The End of Poverty: Economic Possibilities for Our Time",
+ "Jeffrey Sachs", 2006),
+ new Publication("Orthodoxy",
+ "G.K. Chesterton", 1908),
+ new Publication(
+ "The Hitchhiker's Guide to the Galaxy",
+ "Douglas Adams", 1979)
+ };
+ ConsoleListControl.List(
+ Publication.Headers, publications);
+ }
+ }
public class ConsoleListControl
{
+ #region HIGHLIGHT
public static void List(string[] headers, IListable[] items)
+ #endregion
{
int[] columnWidths = DisplayHeaders(headers);
for(int count = 0; count < items.Length; count++)
{
+ #region HIGHLIGHT
string?[] values = items[count].CellValues;
+ #endregion
DisplayItemRow(columnWidths, values);
}
}
/// <returns>Returns an array of column widths</returns>
private static int[] DisplayHeaders(string[] headers)
{
+ #region EXCLUDE
var columnWidths = new int[headers.Length];
for(int index = 0; index < headers.Length; index++)
{
}
Console.WriteLine();
return columnWidths;
+ #endregion
}
private static void DisplayItemRow(
int[] columnWidths, string?[] values)
{
+ #region EXCLUDE
if (columnWidths.Length != values.Length)
{
throw new ArgumentOutOfRangeException(
Console.Write(itemToPrint);
}
Console.WriteLine();
+ #endregion
}
}
+ #endregion
}

MODIFY
src/Chapter08/Listing08.03.ImplementingAnInterface.cs
src/Chapter08/Listing08.03.ImplementingAnInterface.cs
using System;
using Listing08_02;
+ #region INCLUDE
+ #region HIGHLIGHT
public class Contact : PdaItem, IListable, IComparable
+ #endregion
{
- // ...
+ #region EXCLUDE
public Contact(string name)
: base(name)
{
Name = name;
}
+ #endregion
#region IComparable Members
/// <summary>
#endregion
#region IListable Members
+ #region HIGHLIGHT
string?[] IListable.CellValues
+ #endregion
{
get
{
}
#endregion
+ #region EXCLUDE
public override string Name
{
get
protected string? Address { get; set; }
static public string GetName(string firstName, string lastName)
=> $"{ firstName } { lastName }";
+ #endregion
}
+ #endregion
}

MODIFY
src/Chapter08/Listing08.04.CallingExplicitInterfaceMemberImplementations.cs
src/Chapter08/Listing08.04.CallingExplicitInterfaceMemberImplementations.cs
@@ -10,6 +10,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter08.Listing08_04
{
public static void Main()
{
+ #region INCLUDE
string?[] values;
Contact contact = new Contact("Inigo Montoya");
@@ -20,9 +21,12 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter08.Listing08_04
// values = contact.CellValues;
// First cast to IListable
+ #region HIGHLIGHT
values = ((IListable)contact).CellValues;
+ #endregion
// ...
+ #endregion
}
}

MODIFY
src/Chapter08/Listing08.05.ExplicitInterfaceImplementation.cs
src/Chapter08/Listing08.05.ExplicitInterfaceImplementation.cs
@@ -26,9 +26,12 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter08.Listing08_05
}
}
+ #region INCLUDE
+ #region HIGHLIGHT
public class Contact : PdaItem, IListable, IComparable
+ #endregion
{
- // ...
+ #region EXCLUDE
public Contact(string name)
: base(name)
{
@@ -60,9 +63,13 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter08.Listing08_05
nameof(obj))
};
#endregion
+ #endregion
#region IListable Members
+
+ #region HIGHLIGHT
string?[] IListable.CellValues
+ #endregion
{
get
{
@@ -77,6 +84,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter08.Listing08_05
}
#endregion
+ #region EXCLUDE
private string? _LastName;
protected string LastName
{
@@ -94,5 +102,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter08.Listing08_05
protected string? Address { get; set; }
static public string GetName(string firstName, string lastName)
=> $"{ firstName } { lastName }";
+ #endregion
}
+ #endregion
}
\ No newline at end of file

MODIFY
src/Chapter08/Listing08.07.DeclarationWithoutContainingInterface.cs
src/Chapter08/Listing08.07.DeclarationWithoutContainingInterface.cs
interface ISettingsProvider : IReadableSettingsProvider
{
+ /*
+ #region INCLUDE
// ERROR: GetSetting() not available on ISettingsProvider
-
- //string ISettingsProvider.GetSetting(
- // string name, string defaultValue)
- //{
+ string ISettingsProvider.GetSetting(
+ string name, string defaultValue)
+ {
// ...
- //}
+ }
+ #endregion
+ */
void SetSetting(string name, string value);
}

MODIFY
src/Chapter08/Listing08.08.UsingABaseInterfaceInTheClassDeclaration.cs
src/Chapter08/Listing08.08.UsingABaseInterfaceInTheClassDeclaration.cs
void SetSetting(string name, string value);
}
- class FileSettingsProvider : ISettingsProvider,
+ #region INCLUDE
+ public class FileSettingsProvider : ISettingsProvider,
+ #region HIGHLIGHT
IReadableSettingsProvider
+ #endregion
{
#region ISettingsProvider Members
public void SetSetting(string name, string value)
#region IReadableSettingsProvider Members
public string GetSetting(string name, string defaultValue)
{
+ #region EXCLUDE
return name + defaultValue; //just returning this for the example
+ #endregion
}
#endregion
}
-
+ #endregion
}

MODIFY
src/Chapter08/Listing08.10.InterfaceExtensionMethods.cs
src/Chapter08/Listing08.10.InterfaceExtensionMethods.cs
using System;
using Listing08_02;
+ #region INCLUDE
public class Program
{
public static void Main()
// ...
};
-
+ #region HIGHLIGHT
// Classes are implicitly converted to
// their supported interfaces
contacts.List(Contact.Headers);
+ #endregion
Console.WriteLine();
Publication[] publications = new Publication[3] {
- new Publication("Celebration of Discipline",
- "Richard Foster", 1978),
+ new Publication("The End of Poverty: Economic Possibilities for Our Time",
+ "Jeffrey Sachs", 2006),
new Publication("Orthodoxy",
"G.K. Chesterton", 1908),
new Publication(
"The Hitchhiker's Guide to the Galaxy",
"Douglas Adams", 1979)
};
+ #region HIGHLIGHT
publications.List(Publication.Headers);
+ #endregion
}
}
- static class Listable
+ public static class Listable
{
+ #region HIGHLIGHT
public static void List(
this IListable[] items, string[] headers)
+ #endregion
{
int[] columnWidths = DisplayHeaders(headers);
}
}
+ #region EXCLUDE
/// <summary>Displays the column headers</summary>
/// <returns>Returns an array of column widths</returns>
private static int[] DisplayHeaders(string[] headers)
}
Console.WriteLine();
}
+ #endregion
}
+ #endregion
}

MODIFY
src/Chapter08/Listing08.11.DerivingOneInterfaceFromAnother.cs
src/Chapter08/Listing08.11.DerivingOneInterfaceFromAnother.cs
@@ -2,6 +2,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter08.Listing08_11
{
using Listing08_09;
+ #region INCLUDE
interface IDistributedSettingsProvider : ISettingsProvider
{
/// <summary>
@@ -27,4 +28,5 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter08.Listing08_11
void SetSetting(
string uri, string name, string value);
}
+ #endregion
}

MODIFY
src/Chapter08/Listing08.12.DefaultImplementedInterfaceMembers.cs
src/Chapter08/Listing08.12.DefaultImplementedInterfaceMembers.cs
@@ -55,6 +55,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter08.Listing08_12
}
}
+ #region INCLUDE
public interface IListable
{
// Return the value of each cell in the row
@@ -63,9 +64,11 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter08.Listing08_12
get;
}
+ #region HIGHLIGHT
ConsoleColor[] CellColors
{
get
+ #endregion
{
var result = new ConsoleColor[CellValues.Length];
// Using generic Array method to populate array
@@ -74,10 +77,12 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter08.Listing08_12
return result;
}
}
+ #region HIGHLIGHT
static public ConsoleColor DefaultColumnColor { get; set; }
+ #endregion
}
-
+ #region EXCLUDE
public abstract class PdaItem
{
public PdaItem(string name)
@@ -87,9 +92,11 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter08.Listing08_12
public virtual string Name { get; set; }
}
+ #endregion
public class Contact : PdaItem, IListable
{
+ #region EXCLUDE
public Contact(string firstName, string lastName,
string address, string phone)
: base(GetName(firstName, lastName))
@@ -104,6 +111,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter08.Listing08_12
public string LastName { get; set; }
public string Address { get; set; }
public string Phone { get; set; }
+ #endregion
#region IListable
string[] IListable.CellValues
@@ -119,8 +127,12 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter08.Listing08_12
};
}
}
+ #region HIGHLIGHT
+ // *** No CellColors implementation *** //
+ #endregion
#endregion IListable
+ #region EXCLUDE
public static string[] Headers
{
get
@@ -134,10 +146,12 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter08.Listing08_12
static public string GetName(string firstName, string lastName)
=> $"{ firstName } { lastName }";
+ #endregion
}
public class Publication : IListable
{
+ #region EXCLUDE
public Publication(string title, string author, int year)
{
Title = title;
@@ -160,6 +174,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter08.Listing08_12
"Year" };
}
}
+ #endregion
#region IListable
string?[] IListable.CellValues
@@ -175,6 +190,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter08.Listing08_12
}
}
+ #region HIGHLIGHT
ConsoleColor[] IListable.CellColors
{
get
@@ -187,12 +203,13 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter08.Listing08_12
}
return result;
}
-
}
+ #endregion
#endregion IListable
// ...
}
+ #endregion
public class ConsoleListControl

MODIFY
src/Chapter08/Listing08.13.CarelesslyRelyingOnAVirtualMethodImplementation.cs
src/Chapter08/Listing08.13.CarelesslyRelyingOnAVirtualMethodImplementation.cs
// TODO: Update listing in Manuscript
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter08.Listing08_13
{
+ #region INCLUDE
public class WorkflowActivity
{
private static void Start()
@@ -18,4 +19,5 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter08.Listing08_13
// Critical code
}
}
+ #endregion
}

MODIFY
src/Chapter08/Listing08.14.ForcingTheDesirableRunEncapsulation.cs
src/Chapter08/Listing08.14.ForcingTheDesirableRunEncapsulation.cs
using System;
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter08.Listing08_14
{
+ #region INCLUDE
public interface IWorkflowActivity
{
// Private and, therefore, not virtual
@@ -51,7 +52,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter08.Listing08_14
"IExecuteProcessActivity.RestoreStandardInOut()...");
}
- class ExecuteProcessActivity : IExecuteProcessActivity
+ public class ExecuteProcessActivity : IExecuteProcessActivity
{
public ExecuteProcessActivity(string executablePath) =>
ExecutableName = executablePath
@@ -110,4 +111,5 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter08.Listing08_14
ExecuteProcessActivity.Run();
}
}
+ #endregion
}

Add Regions to chapter 8