From 7bf67117c96847f0a92f84a798b557b210aa2eb4 Mon Sep 17 00:00:00 2001 From: Austen Frostad Date: Fri, 9 Dec 2022 12:57:26 -0800 Subject: [PATCH] add wrapper file so 1.1 can be run --- src/Chapter01/Chapter01.csproj | 2 +- .../TopLevelStatementWrapperForListing01.01.cs | 16 ++++++++++++++++ src/Shared/Program.cs | 11 +---------- 3 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 src/Chapter01/TopLevelStatementWrapperForListing01.01.cs diff --git a/src/Chapter01/Chapter01.csproj b/src/Chapter01/Chapter01.csproj index acd04e7eb..ba8ee1415 100644 --- a/src/Chapter01/Chapter01.csproj +++ b/src/Chapter01/Chapter01.csproj @@ -1,4 +1,4 @@ - + 01 $(ExpectedWarnings) diff --git a/src/Chapter01/TopLevelStatementWrapperForListing01.01.cs b/src/Chapter01/TopLevelStatementWrapperForListing01.01.cs new file mode 100644 index 000000000..581ef71f1 --- /dev/null +++ b/src/Chapter01/TopLevelStatementWrapperForListing01.01.cs @@ -0,0 +1,16 @@ +// See https://aka.ms/new-console-template for more information +// this file redirects debug break points to Listing01.01.HelloWorldInC#.cs +// allowing for the appearance that the top-level statement file of Listing01.01.HelloWorldInC#.cs is what is being ran. +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_01 +{ + public class HelloWorld + { + public static void Main() + { + // the #line directive reroutes the debugger's line mapper from this file to "Listing01.01.HelloWorldInC#.cs" + // see https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives#error-and-warning-information +#line (3,1) - (3,55) 13 "Listing01.01.HelloWorldInC#.cs" + Console.WriteLine("Hello. My name is Inigo Montoya."); + } + } +} \ No newline at end of file diff --git a/src/Shared/Program.cs b/src/Shared/Program.cs index 078d92c96..f34a0e299 100644 --- a/src/Shared/Program.cs +++ b/src/Shared/Program.cs @@ -1,4 +1,4 @@ -using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; using System.Reflection; using System.Runtime.CompilerServices; using System.Text.RegularExpressions; @@ -41,15 +41,6 @@ public static async Task Main(string[] args) { input = ParseListingName(input); - // We handle listing 1.1 specially since the listing is a top level statement and - // the file (Listing01.01.HelloWorldInC#.cs) is set to not build as part of the project. - if(input == "01_01") - { - throw new InvalidOperationException( - "This listing (HelloWorld) is left as an exercise for the reader on the command line. "); - } - - Regex reg = new($"Listing{input}\\.+"); IEnumerable targets = assembly.GetTypes().Where(type =>