Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Processing manuscript comments in Chapter 7 #564

Merged
merged 2 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions src/Chapter07/Listing07.20.TypeCheckingWithIsOperator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,6 @@ public static void Main(params string[] args)
nameof(Employee)} object.");
}
}
#region HIGHLIGHT
else if (entity is Employee)
#endregion HIGHLIGHT
{
throw new InvalidOperationException(
$"Entity ({entity.GetType().FullName
}) is unexpectedly an {nameof(Employee)} object.");
}
else if(entity is null)
{
Console.WriteLine(
Expand Down
16 changes: 8 additions & 8 deletions src/Chapter07/Listing07.33.ListPatternMatching.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ public static void Main(string[] args)
// e.g. --help, /h, -h, /?, -?
DisplayHelp();
break;
case [ ['/' or '-', char command], ..]:
// Command begins with '/', '-' and has 0 or more arguments.
if(!ExecuteCommand($"{command}", args[1..]))
case [ ['/' or '-', char option], ..]:
// Option begins with '/', '-' and has 0 or more arguments.
if(!EvaluateOption($"{option}", args[1..]))
{
DisplayHelp();
}
break;
case [ ['-', '-', ..] command, ..]:
// Command begins with "--" and has 0 or more arguments.
if(!ExecuteCommand(command[2..], args[1..]))
case [ ['-', '-', ..] option, ..]:
// Option begins with "--" and has 0 or more arguments.
if(!EvaluateOption(option[2..], args[1..]))
{
DisplayHelp();
}
Expand All @@ -45,8 +45,8 @@ public static void Main(string[] args)
}
}

private static bool ExecuteCommand(string command, string[] args) =>
(command, args) switch
private static bool EvaluateOption(string option, string[] args) =>
(option, args) switch
{
("cat" or "c", [string fileName]) =>
CatalogFile(fileName),
Expand Down