Add remaining regions
MODIFY
src/Chapter06/Listing06.39.DeclaringAStaticField.cs
src/Chapter06/Listing06.39.DeclaringAStaticField.cs
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_39
{
- class Employee
+ #region INCLUDE
+ public class Employee
{
public Employee(string firstName, string lastName)
{
FirstName = firstName;
LastName = lastName;
+ #region HIGHLIGHT
Id = NextId;
NextId++;
+ #endregion
}
// ...
+ #region HIGHLIGHT
public static int NextId;
-
+ #endregion
public int Id { get; private set; }
public string FirstName { get; set; }
public string LastName { get; set; }
@@ -21,4 +25,5 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_39
// ...
}
+ #endregion
}

MODIFY
src/Chapter06/Listing06.40.AssigningAStaticFieldAtDeclaration.cs
src/Chapter06/Listing06.40.AssigningAStaticFieldAtDeclaration.cs
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_40
{
- class Employee
+ #region INCLUDE
+ public class Employee
{
// ...
+ #region HIGHLIGHT
public static int NextId = 42;
+ #endregion
// ...
}
+ #endregion
}

MODIFY
src/Chapter06/Listing06.41.AccessingAStaticField.cs
src/Chapter06/Listing06.41.AccessingAStaticField.cs
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_41
{
+ #region INCLUDE
using System;
public class Program
{
public static void Main()
{
+ #region HIGHLIGHT
Employee.NextId = 1000000;
+ #endregion
Employee employee1 = new Employee(
"Inigo", "Montoya");
@@ -24,11 +27,13 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_41
employee2.LastName,
employee2.Id);
+ #region HIGHLIGHT
Console.WriteLine(
$"NextId = {Employee.NextId}");
+ #endregion
}
}
-
+ #region EXCLUDE
public class Employee
{
public Employee(string firstName, string lastName)
@@ -49,4 +54,6 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_41
public string LastName { get; set; }
public string? Salary { get; set; } = "Not Enough";
}
+ #endregion
+ #endregion
}

MODIFY
src/Chapter06/Listing06.42.DefiningAStaticMethodOnDirectoryInfo.cs
src/Chapter06/Listing06.42.DefiningAStaticMethodOnDirectoryInfo.cs
@@ -5,22 +5,14 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_42
public class Program
{
- public static void Main()
- {
- // ...
- DirectoryInfo directory = new DirectoryInfo(".\\Source");
- directory.MoveTo(".\\Root");
- DirectoryInfoExtension.CopyTo(
- directory, ".\\Target",
- SearchOption.AllDirectories, "*");
- // ...
- }
-
+ #region INCLUDE
public static class DirectoryInfoExtension
{
+ #region HIGHLIGHT
public static void CopyTo(
DirectoryInfo sourceDirectory, string target,
SearchOption option, string searchPattern)
+ #endregion
{
if(target[target.Length - 1] !=
Path.DirectorySeparatorChar)
@@ -61,5 +53,21 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_42
Console.WriteLine("Copying " + fileName);
}
}
+
+ #region EXCLUDE
+ public static void Main()
+ {
+ #endregion
+ DirectoryInfo directory = new DirectoryInfo(".\\Source");
+ directory.MoveTo(".\\Root");
+ #region HIGHLIGHT
+ DirectoryInfoExtension.CopyTo(
+ directory, ".\\Target",
+ SearchOption.AllDirectories, "*");
+ #endregion
+ #region EXCLUDE
+ }
+ #endregion
+ #endregion
}
}

MODIFY
src/Chapter06/Listing06.43.DeclaringAStaticConstructor.cs
src/Chapter06/Listing06.43.DeclaringAStaticConstructor.cs
@@ -2,7 +2,8 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_43
{
using System;
- class Employee
+ #region INCLUDE
+ public class Employee
{
static Employee()
{
@@ -14,4 +15,5 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_43
public static int NextId = 42;
// ...
}
+ #endregion
}

MODIFY
src/Chapter06/Listing06.44.DeclaringAStaticProperty.cs
src/Chapter06/Listing06.44.DeclaringAStaticProperty.cs
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_44
{
- class Employee
+ #region INCLUDE
+ public class Employee
{
// ...
+ #region HIGHLIGHT
public static int NextId
{
get
@@ -15,6 +17,8 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_44
}
}
public static int _NextId = 42;
+ #endregion
// ...
}
+ #endregion
}

MODIFY
src/Chapter06/Listing06.45.DeclaringAStaticClass.cs
src/Chapter06/Listing06.45.DeclaringAStaticClass.cs
@@ -3,7 +3,10 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_45
using System;
using static SimpleMath;
+ #region INCLUDE
+ #region HIGHLIGHT
public static class SimpleMath
+ #endregion
{
// params allows the number of parameters to vary
public static int Max(params int[] numbers)
@@ -34,7 +37,6 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_45
// Check that there is at least one item in numbers
if(numbers.Length == 0)
{
- // TODO: Update listing in Manuscript
throw new ArgumentException(
"numbers cannot be empty", nameof(numbers));
}
@@ -63,12 +65,13 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_45
}
Console.WriteLine(
- $@"Longest argument length = { Max(numbers) }");
+ $@"Longest argument length = {
+ Max(numbers) }");
Console.WriteLine(
$@"Shortest argument length = {
- SimpleMath.Min(numbers) }");
+ Min(numbers) }");
}
}
-
+ #endregion
}

MODIFY
src/Chapter06/Listing06.46.StaticCopyMethodForDirectoryInfo.cs
src/Chapter06/Listing06.46.StaticCopyMethodForDirectoryInfo.cs
@@ -3,21 +3,16 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_46
using System;
using System.IO;
- public class Program
- {
- public static void Main()
- {
- DirectoryInfo directory = new DirectoryInfo(".\\Source");
- directory.CopyTo(".\\Target",
- SearchOption.TopDirectoryOnly, "*");//Extension method. Is Defined below but appears to be a member of the DirectoryInfo object, directory, defined aboves
- }
- }
+ #region INCLUDE
public static class DirectoryInfoExtension
{
public static void CopyTo(
+ #region HIGHLIGHT
this DirectoryInfo sourceDirectory, string target,
+ #endregion
SearchOption option, string searchPattern)
{
+ #region EXCLUDE
if (target[target.Length - 1] != Path.DirectorySeparatorChar)
{
target += Path.DirectorySeparatorChar;
@@ -50,12 +45,30 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_46
searchPattern);
}
}
-
}
private static void Copy(string element, string fileName, string searchPattern)
{
Console.WriteLine("Copying " + fileName);
+ #endregion
+ }
+ }
+
+ #region EXCLUDE
+ public class Program
+ {
+ public static void Main()
+ {
+ #endregion
+ DirectoryInfo directory = new DirectoryInfo(".\\Source");
+ #region HIGHLIGHT
+ directory.CopyTo(".\\Target",
+ SearchOption.TopDirectoryOnly, "*");
+ #endregion
+ #region EXCLUDE
+ //Extension method. Is Defined above but appears to be a member of the DirectoryInfo object, directory, defined aboves
}
}
+ #endregion
+ #endregion
}

MODIFY
src/Chapter06/Listing06.47.DeclaringAConstantField.cs
src/Chapter06/Listing06.47.DeclaringAConstantField.cs
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_47
{
- class ConvertUnits
+ #region INCLUDE
+ public class ConvertUnits
{
public const float CentimetersPerInch = 2.54F;
public const int CupsPerGallon = 16;
// ...
}
+ #endregion
}

MODIFY
src/Chapter06/Listing06.48.DeclaringAFieldAsReadonly.cs
src/Chapter06/Listing06.48.DeclaringAFieldAsReadonly.cs
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_48
{
- class Employee
+ #region INCLUDE
+ public class Employee
{
public Employee(int id)
{
@@ -9,7 +10,9 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_48
// ...
+ #region HIGHLIGHT
private readonly int _Id;
+ #endregion
public int Id
{
get { return _Id; }
@@ -23,4 +26,5 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_48
// ...
}
+ #endregion
}

MODIFY
src/Chapter06/Listing06.49.DeclaringAReadOnlyAutomaticallyImplementedProperty.cs
src/Chapter06/Listing06.49.DeclaringAReadOnlyAutomaticallyImplementedProperty.cs
@@ -25,7 +25,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_49
}
}
-
+ #region INCLUDE
class TicTacToeBoard
{
// Set both player's initial board to all false (blank)
@@ -35,8 +35,9 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_49
// ---+---+--- ---+---+---
// | | | |
// Player 1 - X Player 2 - O
+ #region HIGHLIGHT
public bool[,,] Cells { get; } = new bool[2, 3, 3];
-
+ #endregion
// Error: The property Cells cannot
// be assigned to because it is read-only
// public void SetCells(bool[,,] value) =>
@@ -44,6 +45,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_49
// ...
}
+ #endregion
class TicTacToeBoardPreCSharp5
{

MODIFY
src/Chapter06/Listing06.50.DefiningANestedClass.cs
src/Chapter06/Listing06.50.DefiningANestedClass.cs
@@ -2,11 +2,15 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_50
{
using System;
+ #region INCLUDE
+ // CommandLine is nested within program
+ #region HIGHLIGHT
public class Program
{
// Define a nested class for processing the command line
private class CommandLine
{
+ #endregion
public CommandLine(string[] arguments)
{
for(int argumentCounter = 0;
@@ -38,7 +42,9 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_50
public static void Main(string[] args)
{
+ #region HIGHLIGHT
CommandLine commandLine = new CommandLine(args);
+ #endregion
// Error handling intentionaly missing for elucidation.
@@ -46,22 +52,30 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_50
{
case "new":
// Create a new employee
+ #region EXCLUDE
Console.WriteLine("'Creating' a new Employee.");
+ #endregion
break;
case "update":
// Update an existing employee's data
+ #region EXCLUDE
Console.WriteLine("'Updating' a new Employee.");
+ #endregion
break;
case "delete":
// Remove an existing employee's file
+ #region EXCLUDE
Console.WriteLine("'Removing' a new Employee.");
+ #endregion
break;
default:
Console.WriteLine(
- "Employee.exe new|update|delete " +
+ "Employee.exe " +
+ "new|update|delete " +
"<id> [firstname] [lastname]");
break;
}
}
}
+ #endregion
}

MODIFY
src/Chapter06/Listing06.51.DefiningAPartialClass.cs
src/Chapter06/Listing06.51.DefiningAPartialClass.cs
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_51
{
+ #region INCLUDE
// File: Program1.cs
partial class Program
{
@@ -9,4 +10,5 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_51
partial class Program
{
}
+ #endregion
}

MODIFY
src/Chapter06/Listing06.52.DefiningANestedClassInASeperatePartialClass.cs
src/Chapter06/Listing06.52.DefiningANestedClassInASeperatePartialClass.cs
@@ -5,7 +5,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_52
{
using System;
-
+ #region INCLUDE
// File: Program.cs
partial class Program
{
@@ -13,12 +13,13 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_52
{
CommandLine commandLine = new CommandLine(args);
- #pragma warning disable CS1522 // Empty switch block
switch(commandLine.Action)
{
- // ...
+ #region EXCLUDE
+ default:
+ break;
+ #endregion
}
- #pragma warning restore CS1522 // Empty switch block
}
}
@@ -28,6 +29,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_52
// Define a nested class for processing the command line
private class CommandLine
{
+ #region EXCLUDE
public CommandLine(string[] args)
{
//not implemented
@@ -39,6 +41,8 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_52
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
+ #endregion
}
}
+ #endregion
}

MODIFY
src/Chapter06/Listing06.53.DefiningAPartialMethodToAccessItsImplementation.cs
src/Chapter06/Listing06.53.DefiningAPartialMethodToAccessItsImplementation.cs
@@ -6,13 +6,16 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_53
{
using System;
+ #region INCLUDE
// File: Person.Designer.cs
public partial class Person
{
#region Extensibility Method Definitions
+ #region HIGHLIGHT
static partial void OnLastNameChanging(string value);
static partial void OnFirstNameChanging(string value);
#endregion
+ #endregion
// ...
public string LastName
@@ -25,7 +28,9 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_53
{
if((_LastName != value))
{
+ #region HIGHLIGHT
OnLastNameChanging(value);
+ #endregion
_LastName = value;
}
}
@@ -43,7 +48,9 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_53
{
if(_FirstName != value)
{
+ #region HIGHLIGHT
OnFirstNameChanging(value);
+ #endregion
_FirstName = value;
}
}
@@ -57,7 +64,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_53
{
static partial void OnLastNameChanging(string value)
{
- if(value == null)
+ if(value is null)
{
throw new ArgumentNullException(nameof(value));
}
@@ -69,6 +76,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_53
}
}
+ #region EXCLUDE
static partial void OnFirstNameChanging(string value)
{
if(value == null)
@@ -83,5 +91,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_53
}
}
+ #endregion
}
+ #endregion
}

Add remaining regions