diff --git a/Directory.Build.props b/Directory.Build.props index 5190e9559..df6011c22 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,10 @@ - disable - $(CSharp8Nullable) - $(TreatWarningsAsErrors) + disable + true + netcoreapp3.0 + Mark Michaelis + Addison Wesley + Copyright © Addison Wesley 2003 \ No newline at end of file diff --git a/Directory.Build.targets b/Directory.Build.targets index eca789cfe..a08419e08 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -1,4 +1,8 @@ + + $(ExpectedWarnings) + $(ExpectedWarnings) + diff --git a/README.md b/README.md index 63b3768a4..154b6d03f 100644 --- a/README.md +++ b/README.md @@ -78,3 +78,5 @@ $ ./RunTests.sh ![Azure DevOps tests (branch)](https://img.shields.io/azure-devops/tests/intelliTect/EssentialCSharp/46/v8.0.svg) ![Azure DevOps coverage (branch)](https://img.shields.io/azure-devops/coverage/intelliTect/EssentialCSharp/46/v8.0.svg) * *Linux*: [![Build status](https://dev.azure.com/intelliTect/EssentialCSharp/_apis/build/status/Branch%20v8.0%20-%20EssentialCSharp-Linux)](https://dev.azure.com/intelliTect/EssentialCSharp/_build/latest?definitionId=45) +![Azure DevOps tests (branch)](https://img.shields.io/azure-devops/tests/intelliTect/EssentialCSharp/45/v8.0.svg) +![Azure DevOps coverage (branch)](https://img.shields.io/azure-devops/coverage/intelliTect/EssentialCSharp/45/v8.0.svg) diff --git a/RenumberListings.ps1 b/RenumberListings.ps1 index c441ceb79..9018ed070 100644 --- a/RenumberListings.ps1 +++ b/RenumberListings.ps1 @@ -9,6 +9,7 @@ Function PadNumber { [string]$number ) + # Should use string.PadLeft(2, '0') instead. if($number -match '(?\d?\d)(?.*)') { return "{0:D2}$($Matches.Suffix)" -f ([int]$Matches.Number) } @@ -199,7 +200,7 @@ Function Update-CodeListingSequence { $NewChapterNumber = $NewChapterNumber.PadLeft(2, '0') if(!$listingNumber) { - $ListingNumber = Get-Item (Join-Path (Join-Path $PSScriptRoot "Chapter$ChapterNumber") "Listing$ChapterNumber.*cs") | Select -ExpandProperty Name | + $ListingNumber = Get-Item (Join-Path (Join-Path $PSScriptRoot 'src' "Chapter$ChapterNumber") "Listing$ChapterNumber.*cs") | Select-Object -ExpandProperty Name | ForEach-Object{ if($_ -match "Listing$ChapterNumber\.(?\d\d)(?.*)") { Write-Output $Matches.Listing @@ -282,7 +283,7 @@ Function Update-CodeListingSequence { # $oldFilePathPattern = (Join-Path (Join-Path $PSScriptRoot "Chapter$ChapterNumber") "Listing$ChapterNumber.$eachListingNumber*.cs") #} #else { - $oldFilePathPattern = (Join-Path (Join-Path $PSScriptRoot "Chapter$ChapterNumber") "Listing$(if($IsIntermediateName.IsPresent){"$ChapterNumber"}else{"$NewChapterNumber.TEMP"}).$eachListingNumber*.cs") + $oldFilePathPattern = (Join-Path (Join-Path $PSScriptRoot 'src' "Chapter$ChapterNumber") "Listing$(if($IsIntermediateName.IsPresent){"$ChapterNumber"}else{"$NewChapterNumber.TEMP"}).$eachListingNumber*.cs") #} $files = @(Get-Item $oldFilePathPattern) diff --git a/src/Chapter.props b/src/Chapter.props new file mode 100644 index 000000000..9d19cf012 --- /dev/null +++ b/src/Chapter.props @@ -0,0 +1,6 @@ + + + Exe + AddisonWesley.Michaelis.EssentialCSharp.Shared.Program + + diff --git a/src/Chapter01.Tests/Chapter01.Tests.csproj b/src/Chapter01.Tests/Chapter01.Tests.csproj index ca19554f4..50f260aca 100644 --- a/src/Chapter01.Tests/Chapter01.Tests.csproj +++ b/src/Chapter01.Tests/Chapter01.Tests.csproj @@ -1,23 +1,10 @@  - - Exe - netcoreapp3.0 + Chapter01.Tests - enable - 8.0 - true - - - - - - - - - + - \ No newline at end of file + diff --git a/src/Chapter01/Chapter01.csproj b/src/Chapter01/Chapter01.csproj index 32861b1b7..c27b0db76 100644 --- a/src/Chapter01/Chapter01.csproj +++ b/src/Chapter01/Chapter01.csproj @@ -1,17 +1,12 @@  - Exe - netcoreapp3.0 Chapter01 - AddisonWesley.Michaelis.EssentialCSharp.Shared.Program - enable - 8.0 - + Program.cs - \ No newline at end of file + diff --git a/src/Chapter01/Chapter01.sln b/src/Chapter01/Chapter01.sln deleted file mode 100644 index e503fffff..000000000 --- a/src/Chapter01/Chapter01.sln +++ /dev/null @@ -1,48 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26127.3 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Chapter01", "Chapter01.csproj", "{70458AA7-C130-4E97-BBD9-C54BDCDF1A67}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Chapter01.Tests", "..\Chapter01.Tests\Chapter01.Tests.csproj", "{EC47C858-464E-4FCC-9668-0CC89FDD5ACC}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|Any CPU = Release|Any CPU - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {70458AA7-C130-4E97-BBD9-C54BDCDF1A67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {70458AA7-C130-4E97-BBD9-C54BDCDF1A67}.Debug|Any CPU.Build.0 = Debug|Any CPU - {70458AA7-C130-4E97-BBD9-C54BDCDF1A67}.Debug|x64.ActiveCfg = Debug|x64 - {70458AA7-C130-4E97-BBD9-C54BDCDF1A67}.Debug|x64.Build.0 = Debug|x64 - {70458AA7-C130-4E97-BBD9-C54BDCDF1A67}.Debug|x86.ActiveCfg = Debug|x86 - {70458AA7-C130-4E97-BBD9-C54BDCDF1A67}.Debug|x86.Build.0 = Debug|x86 - {70458AA7-C130-4E97-BBD9-C54BDCDF1A67}.Release|Any CPU.ActiveCfg = Release|Any CPU - {70458AA7-C130-4E97-BBD9-C54BDCDF1A67}.Release|Any CPU.Build.0 = Release|Any CPU - {70458AA7-C130-4E97-BBD9-C54BDCDF1A67}.Release|x64.ActiveCfg = Release|x64 - {70458AA7-C130-4E97-BBD9-C54BDCDF1A67}.Release|x64.Build.0 = Release|x64 - {70458AA7-C130-4E97-BBD9-C54BDCDF1A67}.Release|x86.ActiveCfg = Release|x86 - {70458AA7-C130-4E97-BBD9-C54BDCDF1A67}.Release|x86.Build.0 = Release|x86 - {EC47C858-464E-4FCC-9668-0CC89FDD5ACC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {EC47C858-464E-4FCC-9668-0CC89FDD5ACC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {EC47C858-464E-4FCC-9668-0CC89FDD5ACC}.Debug|x64.ActiveCfg = Debug|x64 - {EC47C858-464E-4FCC-9668-0CC89FDD5ACC}.Debug|x64.Build.0 = Debug|x64 - {EC47C858-464E-4FCC-9668-0CC89FDD5ACC}.Debug|x86.ActiveCfg = Debug|x86 - {EC47C858-464E-4FCC-9668-0CC89FDD5ACC}.Debug|x86.Build.0 = Debug|x86 - {EC47C858-464E-4FCC-9668-0CC89FDD5ACC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {EC47C858-464E-4FCC-9668-0CC89FDD5ACC}.Release|Any CPU.Build.0 = Release|Any CPU - {EC47C858-464E-4FCC-9668-0CC89FDD5ACC}.Release|x64.ActiveCfg = Release|x64 - {EC47C858-464E-4FCC-9668-0CC89FDD5ACC}.Release|x64.Build.0 = Release|x64 - {EC47C858-464E-4FCC-9668-0CC89FDD5ACC}.Release|x86.ActiveCfg = Release|x86 - {EC47C858-464E-4FCC-9668-0CC89FDD5ACC}.Release|x86.Build.0 = Release|x86 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/src/Chapter02.Tests/Chapter02.Tests.csproj b/src/Chapter02.Tests/Chapter02.Tests.csproj index 689ebf040..42e84351d 100644 --- a/src/Chapter02.Tests/Chapter02.Tests.csproj +++ b/src/Chapter02.Tests/Chapter02.Tests.csproj @@ -1,25 +1,12 @@  - Exe - netcoreapp3.0 Chapter02.Tests - enable - 8.0 - true - - - + - - - - - - - \ No newline at end of file + diff --git a/src/Chapter02/Chapter02.csproj b/src/Chapter02/Chapter02.csproj index 50ad1853e..f238ea398 100644 --- a/src/Chapter02/Chapter02.csproj +++ b/src/Chapter02/Chapter02.csproj @@ -1,17 +1,12 @@  - Exe - netcoreapp3.0 Chapter02 - AddisonWesley.Michaelis.EssentialCSharp.Shared.Program - enable - 8.0 - + Program.cs - \ No newline at end of file + diff --git a/src/Chapter03.Tests/Chapter03.Tests.csproj b/src/Chapter03.Tests/Chapter03.Tests.csproj index 5c20caff6..2aa536882 100644 --- a/src/Chapter03.Tests/Chapter03.Tests.csproj +++ b/src/Chapter03.Tests/Chapter03.Tests.csproj @@ -1,22 +1,9 @@  - Exe - netcoreapp3.0 Chapter03.Tests - enable - 8.0 - true - - - - - - - - - + - \ No newline at end of file + diff --git a/src/Chapter03/Chapter03.csproj b/src/Chapter03/Chapter03.csproj index 84a6ea60a..b47be1535 100644 --- a/src/Chapter03/Chapter03.csproj +++ b/src/Chapter03/Chapter03.csproj @@ -1,16 +1,14 @@  - Exe - netcoreapp3.0 Chapter03 - AddisonWesley.Michaelis.EssentialCSharp.Shared.Program - enable - 8.0 - + + + + Program.cs - \ No newline at end of file + diff --git a/src/Chapter03/Listing03.01.CheckingForNull.cs b/src/Chapter03/Listing03.01.CheckingForNull.cs new file mode 100644 index 000000000..006d3dc94 --- /dev/null +++ b/src/Chapter03/Listing03.01.CheckingForNull.cs @@ -0,0 +1,23 @@ +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_01 +{ + public class Program + { + public static void Main() + { + int? number = null; + // ... + if (number is null) + { + System.Console.WriteLine( + $"{ nameof(number) } requires a value and cannot be null"); + } + else + { + System.Console.WriteLine( + $"{ nameof(number) } is of type { number.GetType() }."); + } + + } + } +} + diff --git a/src/Chapter03/Listing03.01.UsingTheNullableModifier.cs b/src/Chapter03/Listing03.01.UsingTheNullableModifier.cs deleted file mode 100644 index 7a4a801b8..000000000 --- a/src/Chapter03/Listing03.01.UsingTheNullableModifier.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_01 -{ - public class Program - { - public static void Main() - { - int? count = null; - do - { - // ... - } - while(count == null); - } - } -} diff --git a/src/Chapter03/Listing03.01B.DereferencingAnUnassignedVariable.cs b/src/Chapter03/Listing03.01B.DereferencingAnUnassignedVariable.cs new file mode 100644 index 000000000..662978dff --- /dev/null +++ b/src/Chapter03/Listing03.01B.DereferencingAnUnassignedVariable.cs @@ -0,0 +1,13 @@ +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_01B +{ + public class Program + { + public static void Main() + { + string? text; + // ... + // Compile Error: Use of unassigned local variable 'text' + // System.Console.WriteLine(text.length); + } + } +} diff --git a/src/Chapter04.Tests/Chapter04.Tests.csproj b/src/Chapter04.Tests/Chapter04.Tests.csproj index 45fd71928..881912027 100644 --- a/src/Chapter04.Tests/Chapter04.Tests.csproj +++ b/src/Chapter04.Tests/Chapter04.Tests.csproj @@ -1,25 +1,12 @@  - Exe - netcoreapp3.0 Chapter04.Tests - enable - 8.0 - true - - - + - - - - - - - \ No newline at end of file + diff --git a/src/Chapter04/Chapter04.csproj b/src/Chapter04/Chapter04.csproj index 323e7db90..2158d5960 100644 --- a/src/Chapter04/Chapter04.csproj +++ b/src/Chapter04/Chapter04.csproj @@ -1,17 +1,12 @@  - Exe - netcoreapp3.0 Chapter04 - AddisonWesley.Michaelis.EssentialCSharp.Shared.Program - enable - 8.0 - 1030 - - 1030 + + + 1030 - + Program.cs diff --git a/src/Chapter05.Tests/Chapter05.Tests.csproj b/src/Chapter05.Tests/Chapter05.Tests.csproj index d0523a5c6..d8deaafbb 100644 --- a/src/Chapter05.Tests/Chapter05.Tests.csproj +++ b/src/Chapter05.Tests/Chapter05.Tests.csproj @@ -1,21 +1,8 @@  - Exe - netcoreapp3.0 Chapter05.Tests - enable - 8.0 - true - - - - - - - - - + @@ -30,4 +17,4 @@ PreserveNewest - \ No newline at end of file + diff --git a/src/Chapter05.Tests/Listing05.12.PassingCommandLineArgumentsToMain.Tests.cs b/src/Chapter05.Tests/Listing05.12.PassingCommandLineArgumentsToMain.Tests.cs index 13a3a42cd..ae2143569 100644 --- a/src/Chapter05.Tests/Listing05.12.PassingCommandLineArgumentsToMain.Tests.cs +++ b/src/Chapter05.Tests/Listing05.12.PassingCommandLineArgumentsToMain.Tests.cs @@ -31,7 +31,7 @@ public void Main_GoodArgs_DownloadFile() { Assert.AreEqual(0, Program.Main(args)); } - catch (AggregateException exception) when(exception.InnerException?.GetType() == typeof(System.Net.Http.HttpRequestException)) + catch (AggregateException exception) when (exception.InnerException!.GetType() == typeof(System.Net.Http.HttpRequestException)) { Assert.Inconclusive("Unable to download the file. Check your Internet connection."); } diff --git a/src/Chapter05/Chapter05.csproj b/src/Chapter05/Chapter05.csproj index 0dcf6272e..8657f53ec 100644 --- a/src/Chapter05/Chapter05.csproj +++ b/src/Chapter05/Chapter05.csproj @@ -1,13 +1,8 @@  - Exe - netcoreapp3.0 Chapter05 - AddisonWesley.Michaelis.EssentialCSharp.Shared.Program - enable - 8.0 - + Program.cs diff --git a/src/Chapter06.Tests/Chapter06.Tests.csproj b/src/Chapter06.Tests/Chapter06.Tests.csproj index efa6e4dc8..6ed6ada17 100644 --- a/src/Chapter06.Tests/Chapter06.Tests.csproj +++ b/src/Chapter06.Tests/Chapter06.Tests.csproj @@ -1,20 +1,9 @@  - Exe - netcoreapp3.0 Chapter08.Tests - enable - 8.0 - - - - - - - - + - \ No newline at end of file + diff --git a/src/Chapter06/Chapter06.csproj b/src/Chapter06/Chapter06.csproj index 574d01bba..d14fdbe20 100644 --- a/src/Chapter06/Chapter06.csproj +++ b/src/Chapter06/Chapter06.csproj @@ -1,16 +1,11 @@ - + - Exe - netcoreapp3.0 Chapter06 - AddisonWesley.Michaelis.EssentialCSharp.Shared.Program - enable - 8.0 - + Program.cs - \ No newline at end of file + diff --git a/src/Chapter06/Listing06.31.OverloadingAConstructor.cs b/src/Chapter06/Listing06.31.OverloadingAConstructor.cs index c059f124a..29042b153 100644 --- a/src/Chapter06/Listing06.31.OverloadingAConstructor.cs +++ b/src/Chapter06/Listing06.31.OverloadingAConstructor.cs @@ -1,5 +1,6 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_31 { +#pragma warning disable 649 // _Id is never assigned public class Employee { public Employee(string firstName, string lastName) @@ -17,7 +18,7 @@ public Employee( } public Employee(int id) => Id = id; - + private int _Id; public int Id { @@ -36,4 +37,5 @@ private set // ... } +#pragma warning restore 649 } diff --git a/src/Chapter07.Tests/Chapter07.Tests.csproj b/src/Chapter07.Tests/Chapter07.Tests.csproj index bf914e8c0..52603aded 100644 --- a/src/Chapter07.Tests/Chapter07.Tests.csproj +++ b/src/Chapter07.Tests/Chapter07.Tests.csproj @@ -1,19 +1,8 @@  - Exe - netcoreapp3.0 Chapter07.Tests - enable - 8.0 - - - - - - - - + diff --git a/src/Chapter07/Chapter07.csproj b/src/Chapter07/Chapter07.csproj index f159cbc53..873dd5c03 100644 --- a/src/Chapter07/Chapter07.csproj +++ b/src/Chapter07/Chapter07.csproj @@ -1,16 +1,15 @@ - + - Exe - netcoreapp3.0 Chapter07 - AddisonWesley.Michaelis.EssentialCSharp.Shared.Program - enable - 8.0 - + + + 0108 + + Program.cs - \ No newline at end of file + diff --git a/src/Chapter08.Tests/Chapter08.Tests.csproj b/src/Chapter08.Tests/Chapter08.Tests.csproj index a843d0ef7..1a5583934 100644 --- a/src/Chapter08.Tests/Chapter08.Tests.csproj +++ b/src/Chapter08.Tests/Chapter08.Tests.csproj @@ -1,20 +1,9 @@  - Exe - netcoreapp3.0 Chapter08.Tests - enable - 8.0 - - - - - - - - + - \ No newline at end of file + diff --git a/src/Chapter08/Chapter08.csproj b/src/Chapter08/Chapter08.csproj index 07628ed31..9295ffe1f 100644 --- a/src/Chapter08/Chapter08.csproj +++ b/src/Chapter08/Chapter08.csproj @@ -1,16 +1,11 @@ - + - Exe - netcoreapp3.0 Chapter08 - AddisonWesley.Michaelis.EssentialCSharp.Shared.Program - enable - 8.0 - + Program.cs - \ No newline at end of file + diff --git a/src/Chapter09.Tests/Chapter09.Tests.csproj b/src/Chapter09.Tests/Chapter09.Tests.csproj index 562e922fb..6f5877882 100644 --- a/src/Chapter09.Tests/Chapter09.Tests.csproj +++ b/src/Chapter09.Tests/Chapter09.Tests.csproj @@ -1,20 +1,9 @@  - Exe - netcoreapp3.0 Chapter09.Tests - enable - 8.0 - - - - - - - - + - \ No newline at end of file + diff --git a/src/Chapter09/Chapter09.csproj b/src/Chapter09/Chapter09.csproj index 8d988debe..3a4fa091b 100644 --- a/src/Chapter09/Chapter09.csproj +++ b/src/Chapter09/Chapter09.csproj @@ -1,13 +1,8 @@ - + - Exe - netcoreapp3.0 Chapter09 - AddisonWesley.Michaelis.EssentialCSharp.Shared.Program - enable - 8.0 - + Program.cs @@ -16,4 +11,4 @@ - \ No newline at end of file + diff --git a/src/Chapter10.Tests/Chapter10.Tests.csproj b/src/Chapter10.Tests/Chapter10.Tests.csproj index bab291c60..5874f9fb8 100644 --- a/src/Chapter10.Tests/Chapter10.Tests.csproj +++ b/src/Chapter10.Tests/Chapter10.Tests.csproj @@ -1,20 +1,9 @@  - Exe - netcoreapp3.0 Chapter10.Tests - enable - 8.0 - - - - - - - - + - \ No newline at end of file + diff --git a/src/Chapter10/Chapter10.csproj b/src/Chapter10/Chapter10.csproj index c166afbc2..f5356c43e 100644 --- a/src/Chapter10/Chapter10.csproj +++ b/src/Chapter10/Chapter10.csproj @@ -1,13 +1,8 @@ - + - Exe - netcoreapp3.0 Chapter10 - AddisonWesley.Michaelis.EssentialCSharp.Shared.Program - enable - 8.0 - + Program.cs @@ -16,4 +11,4 @@ - \ No newline at end of file + diff --git a/src/Chapter11.Tests/Chapter11.Tests.csproj b/src/Chapter11.Tests/Chapter11.Tests.csproj index 10b5175a4..173df15fe 100644 --- a/src/Chapter11.Tests/Chapter11.Tests.csproj +++ b/src/Chapter11.Tests/Chapter11.Tests.csproj @@ -1,19 +1,9 @@ - - - Exe - netcoreapp3.0 - Chapter11.Tests - enable - 8.0 - - - - - - - - - - - - + + + Chapter11.Tests + + + + + + diff --git a/src/Chapter11/Chapter11.csproj b/src/Chapter11/Chapter11.csproj index 3f56b71eb..201930ade 100644 --- a/src/Chapter11/Chapter11.csproj +++ b/src/Chapter11/Chapter11.csproj @@ -1,18 +1,13 @@ - - - Exe - netcoreapp3.0 - Chapter11 - AddisonWesley.Michaelis.EssentialCSharp.Shared.Program - enable - 8.0 - - - - - - - Program.cs - - - \ No newline at end of file + + + Chapter11 + + + + + + + Program.cs + + + diff --git a/src/Chapter11/Listing11.02.CatchingDifferentExceptionTypes.cs b/src/Chapter11/Listing11.02.CatchingDifferentExceptionTypes.cs index 7b34645e6..40b05bc58 100644 --- a/src/Chapter11/Listing11.02.CatchingDifferentExceptionTypes.cs +++ b/src/Chapter11/Listing11.02.CatchingDifferentExceptionTypes.cs @@ -11,7 +11,8 @@ public static void Main(string[] args) { try { - throw new Win32Exception(42); + //throw new Win32Exception(42); + // ... //TextNumberParser.Parse("negative forty-two"); // ... throw new InvalidOperationException( @@ -19,9 +20,10 @@ public static void Main(string[] args) // ... } catch(Win32Exception exception) - when(args.Length == exception.NativeErrorCode) + when(exception.NativeErrorCode == 42) { - + // Handle Win32Exception where + // ErrorCode is 42 } catch(NullReferenceException exception) { @@ -33,7 +35,7 @@ public static void Main(string[] args) } catch(InvalidOperationException exception) { - // Handle ApplicationException + // Handle InvalidOperationException } catch(Exception exception) { diff --git a/src/Chapter12.Tests/Chapter12.Tests.csproj b/src/Chapter12.Tests/Chapter12.Tests.csproj index ef8ae29c1..bb751f329 100644 --- a/src/Chapter12.Tests/Chapter12.Tests.csproj +++ b/src/Chapter12.Tests/Chapter12.Tests.csproj @@ -1,20 +1,9 @@  - Exe - netcoreapp3.0 Chapter12.Tests - enable - 8.0 - - - - - - - - + - \ No newline at end of file + diff --git a/src/Chapter12/Chapter12.csproj b/src/Chapter12/Chapter12.csproj index fd033d0e9..928631a0b 100644 --- a/src/Chapter12/Chapter12.csproj +++ b/src/Chapter12/Chapter12.csproj @@ -1,13 +1,8 @@  - Exe - netcoreapp3.0 Chapter12 - AddisonWesley.Michaelis.EssentialCSharp.Shared.Program - enable - 8.0 - + Program.cs diff --git a/src/Chapter13.Tests/Chapter13.Tests.csproj b/src/Chapter13.Tests/Chapter13.Tests.csproj index ddf740592..85774d342 100644 --- a/src/Chapter13.Tests/Chapter13.Tests.csproj +++ b/src/Chapter13.Tests/Chapter13.Tests.csproj @@ -1,20 +1,9 @@  - Exe - netcoreapp3.0 Chapter13.Tests - enable - 8.0 - - - - - - - - + - \ No newline at end of file + diff --git a/src/Chapter13/Chapter13.csproj b/src/Chapter13/Chapter13.csproj index ebbe23cb1..4d5591595 100644 --- a/src/Chapter13/Chapter13.csproj +++ b/src/Chapter13/Chapter13.csproj @@ -1,16 +1,11 @@ - + - Exe - netcoreapp3.0 Chapter13 - AddisonWesley.Michaelis.EssentialCSharp.Shared.Program - enable - 8.0 - + Program.cs - \ No newline at end of file + diff --git a/src/Chapter14.Tests/Chapter14.Tests.csproj b/src/Chapter14.Tests/Chapter14.Tests.csproj index bb536fd0a..f2e1de10a 100644 --- a/src/Chapter14.Tests/Chapter14.Tests.csproj +++ b/src/Chapter14.Tests/Chapter14.Tests.csproj @@ -1,21 +1,12 @@  - Exe - netcoreapp3.0 Chapter14.Tests - enable - 8.0 - - + - - - - - \ No newline at end of file + diff --git a/src/Chapter14/Chapter14.csproj b/src/Chapter14/Chapter14.csproj index 0b6715d79..b18a59f41 100644 --- a/src/Chapter14/Chapter14.csproj +++ b/src/Chapter14/Chapter14.csproj @@ -1,17 +1,12 @@ - + - Exe - netcoreapp3.0 Chapter14 - AddisonWesley.Michaelis.EssentialCSharp.Shared.Program - enable - 8.0 - + Program.cs - \ No newline at end of file + diff --git a/src/Chapter14/Listing14.13.UsingTheEventKeywordWithTheEventCodingPattern.cs b/src/Chapter14/Listing14.13.UsingTheEventKeywordWithTheEventCodingPattern.cs index 233920e6f..016f2aaf8 100644 --- a/src/Chapter14/Listing14.13.UsingTheEventKeywordWithTheEventCodingPattern.cs +++ b/src/Chapter14/Listing14.13.UsingTheEventKeywordWithTheEventCodingPattern.cs @@ -1,6 +1,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_13 { using System; +#pragma warning disable 67 // OnTemperatureChange is declared but never used public class Thermostat { @@ -25,4 +26,5 @@ public float CurrentTemperature } private float _CurrentTemperature; } +#pragma warning restore 67 } \ No newline at end of file diff --git a/src/Chapter15.Tests/Chapter15.Tests.csproj b/src/Chapter15.Tests/Chapter15.Tests.csproj index b101554ec..4f7e20f11 100644 --- a/src/Chapter15.Tests/Chapter15.Tests.csproj +++ b/src/Chapter15.Tests/Chapter15.Tests.csproj @@ -1,20 +1,9 @@  - Exe - netcoreapp3.0 Chapter15.Tests - enable - 8.0 - - - - - - - - + - \ No newline at end of file + diff --git a/src/Chapter15/Chapter15.csproj b/src/Chapter15/Chapter15.csproj index c5dde6946..905d93c84 100644 --- a/src/Chapter15/Chapter15.csproj +++ b/src/Chapter15/Chapter15.csproj @@ -1,17 +1,12 @@ - + - Exe - netcoreapp3.0 Chapter15 - AddisonWesley.Michaelis.EssentialCSharp.Shared.Program - enable - 8.0 - + Program.cs - \ No newline at end of file + diff --git a/src/Chapter16.Tests/Chapter16.Tests.csproj b/src/Chapter16.Tests/Chapter16.Tests.csproj index a4bfe23ea..01cc5326e 100644 --- a/src/Chapter16.Tests/Chapter16.Tests.csproj +++ b/src/Chapter16.Tests/Chapter16.Tests.csproj @@ -1,20 +1,9 @@  - Exe - netcoreapp3.0 Chapter16.Tests - enable - 8.0 - - - - - - - - + - \ No newline at end of file + diff --git a/src/Chapter16/Chapter16.csproj b/src/Chapter16/Chapter16.csproj index 996346175..b3a216b2d 100644 --- a/src/Chapter16/Chapter16.csproj +++ b/src/Chapter16/Chapter16.csproj @@ -1,17 +1,12 @@ - + - Exe - netcoreapp3.0 Chapter16 - AddisonWesley.Michaelis.EssentialCSharp.Shared.Program - enable - 8.0 - + Program.cs - \ No newline at end of file + diff --git a/src/Chapter17.Tests/Chapter17.Tests.csproj b/src/Chapter17.Tests/Chapter17.Tests.csproj index 5b3204e10..c0ffa132c 100644 --- a/src/Chapter17.Tests/Chapter17.Tests.csproj +++ b/src/Chapter17.Tests/Chapter17.Tests.csproj @@ -1,20 +1,9 @@  - Exe - netcoreapp3.0 Chapter17.Tests - enable - 8.0 - - - - - - - - + - \ No newline at end of file + diff --git a/src/Chapter17/Chapter17.csproj b/src/Chapter17/Chapter17.csproj index f0707d548..6b47b7f77 100644 --- a/src/Chapter17/Chapter17.csproj +++ b/src/Chapter17/Chapter17.csproj @@ -1,17 +1,12 @@ - + - Exe - netcoreapp3.0 Chapter17 - AddisonWesley.Michaelis.EssentialCSharp.Shared.Program - enable - 8.0 - + Program.cs - \ No newline at end of file + diff --git a/src/Chapter18.Tests/Chapter18.Tests.csproj b/src/Chapter18.Tests/Chapter18.Tests.csproj index 2fc0c14a6..05fdf045f 100644 --- a/src/Chapter18.Tests/Chapter18.Tests.csproj +++ b/src/Chapter18.Tests/Chapter18.Tests.csproj @@ -1,20 +1,9 @@  - Exe - netcoreapp3.0 Chapter18.Tests - enable - 8.0 - - - - - - - - + - \ No newline at end of file + diff --git a/src/Chapter18/Chapter18.csproj b/src/Chapter18/Chapter18.csproj index f62810763..cdbb6349e 100644 --- a/src/Chapter18/Chapter18.csproj +++ b/src/Chapter18/Chapter18.csproj @@ -1,13 +1,12 @@ - + - Exe - netcoreapp3.0 Chapter18 - AddisonWesley.Michaelis.EssentialCSharp.Shared.Program - enable - 8.0 - + + + 0612 + + @@ -25,4 +24,4 @@ DoWorkEventArgs.cs - \ No newline at end of file + diff --git a/src/Chapter19.Tests/Chapter19.Tests.csproj b/src/Chapter19.Tests/Chapter19.Tests.csproj index 460a98367..68ebfa1ad 100644 --- a/src/Chapter19.Tests/Chapter19.Tests.csproj +++ b/src/Chapter19.Tests/Chapter19.Tests.csproj @@ -1,17 +1,7 @@  - netcoreapp3.0 - enable - 8.0 - - - - - - - - + diff --git a/src/Chapter19/Chapter19.csproj b/src/Chapter19/Chapter19.csproj index 5aeabac09..f5aec945a 100644 --- a/src/Chapter19/Chapter19.csproj +++ b/src/Chapter19/Chapter19.csproj @@ -1,13 +1,8 @@ - + - Exe - netcoreapp3.0 Chapter19 - AddisonWesley.Michaelis.EssentialCSharp.Shared.Program - enable - 8.0 - + Program.cs @@ -22,4 +17,4 @@ PiCalculator.cs - \ No newline at end of file + diff --git a/src/Chapter20.Tests/Chapter20.Tests.csproj b/src/Chapter20.Tests/Chapter20.Tests.csproj index 265206bfd..f105ca5cc 100644 --- a/src/Chapter20.Tests/Chapter20.Tests.csproj +++ b/src/Chapter20.Tests/Chapter20.Tests.csproj @@ -1,17 +1,7 @@  - netcoreapp3.0 - enable - 8.0 - - - - - - - - + diff --git a/src/Chapter20/Chapter20.csproj b/src/Chapter20/Chapter20.csproj index 6d4b1c7ed..f47000981 100644 --- a/src/Chapter20/Chapter20.csproj +++ b/src/Chapter20/Chapter20.csproj @@ -1,15 +1,10 @@ - + - Exe - netcoreapp3.0 Chapter20 2 True - AddisonWesley.Michaelis.EssentialCSharp.Shared.Program - enable - 8.0 - + @@ -18,4 +13,4 @@ Program.cs - \ No newline at end of file + diff --git a/src/Chapter21.Tests/Chapter21.Tests.csproj b/src/Chapter21.Tests/Chapter21.Tests.csproj index 13334a947..7713e0cbc 100644 --- a/src/Chapter21.Tests/Chapter21.Tests.csproj +++ b/src/Chapter21.Tests/Chapter21.Tests.csproj @@ -1,17 +1,7 @@  - netcoreapp3.0 - enable - 8.0 - - - - - - - - + diff --git a/src/Chapter21/Chapter21.csproj b/src/Chapter21/Chapter21.csproj index e11e86422..063560401 100644 --- a/src/Chapter21/Chapter21.csproj +++ b/src/Chapter21/Chapter21.csproj @@ -1,14 +1,9 @@ - + - Exe - netcoreapp3.0 Chapter21 True - AddisonWesley.Michaelis.EssentialCSharp.Shared.Program - enable - 8.0 - + Program.cs @@ -17,4 +12,4 @@ - \ No newline at end of file + diff --git a/src/ChapterTests.targets b/src/ChapterTests.props similarity index 55% rename from src/ChapterTests.targets rename to src/ChapterTests.props index 07cf4f077..673d71c76 100644 --- a/src/ChapterTests.targets +++ b/src/ChapterTests.props @@ -4,5 +4,9 @@ --> + + + + \ No newline at end of file diff --git a/src/Shared/NetCore.cs b/src/Shared/NetCore.cs index e876132be..15e77ead6 100644 --- a/src/Shared/NetCore.cs +++ b/src/Shared/NetCore.cs @@ -1,14 +1,14 @@ -using System; +using System; using System.Reflection; - +#nullable enable public class NetCore { public static string GetNetCoreVersion() { Assembly assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly; - string[] assemblyPath = assembly!.CodeBase!.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries); + string[] assemblyPath = assembly.CodeBase!.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries); int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App"); - if (netCoreAppIndex >= 0 && netCoreAppIndex < assemblyPath.Length - 2) + if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2) return assemblyPath[netCoreAppIndex + 1]; throw new Exception("Unable to determine .NET Core version."); } diff --git a/src/Shared/Program.cs b/src/Shared/Program.cs index 561d400c9..46828e391 100644 --- a/src/Shared/Program.cs +++ b/src/Shared/Program.cs @@ -16,8 +16,11 @@ public static void Main(string[] args) { string input; IEnumerable stringArguments = new string[0]; - var assembly = Assembly.GetEntryAssembly(); - + Assembly assembly = Assembly.GetEntryAssembly()!; + if (assembly is null) + { + throw new InvalidOperationException("Unable to retrieve the EntryAssembly."); + } string regexMatch = Regex.Match(assembly.GetName().Name, "\\d{1,2}").Value; int chapterNumber = int.Parse(regexMatch); @@ -45,7 +48,7 @@ public static void Main(string[] args) Regex reg = new Regex($"{input}\\.+"); Type? target = assembly.GetTypes().FirstOrDefault(type => { - return reg.IsMatch(type.FullName); + return reg.IsMatch(type.FullName!); }); if (target == null) { @@ -76,7 +79,7 @@ public static void Main(string[] args) { Thread thread = new Thread(() => { - object result = method.Invoke(null, arguments); + object? result = method.Invoke(null, arguments); if (!(method.ReturnType == typeof(void))) { Console.WriteLine($"Result: {result}"); @@ -85,7 +88,7 @@ public static void Main(string[] args) } else { - var result = method.Invoke(null, arguments); + object? result = method.Invoke(null, arguments); if (!(method.ReturnType == typeof(void))) { @@ -115,28 +118,28 @@ public static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("----Exception----"); - if (exception.InnerException != null) + if (exception.InnerException is null) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine(string.Format("Listing {0} threw an exception of type {1}.", input, + exception.GetType())); + } + else { // Invoke ExceptionDispatchInfo using reflection because it doesn't // exist in .NET 4.0 or earlier and we want to maintain compatibility // while still taking advantage of it if it is available. - Type exceptionDispatchInfoType = - Type.GetType( - "System.Runtime.ExceptionServices.ExceptionDispatchInfo"); - if (exceptionDispatchInfoType != null) + Type? exceptionDispatchInfoType = + // Don't use nameof here as the type may not exists and, therefore, won't compile. + Type.GetType("System.Runtime.ExceptionServices.ExceptionDispatchInfo"); + if (exceptionDispatchInfoType is null) + throw exception.InnerException; + else { dynamic exceptionDispatchInfo = exceptionDispatchInfoType.GetMethod("Capture") - .Invoke(exceptionDispatchInfoType, new object[] {exception.InnerException}); + !.Invoke(exceptionDispatchInfoType, new object[] { exception.InnerException })!; exceptionDispatchInfo.Throw(); } - else - throw exception.InnerException; - } - else - { - Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine(string.Format("Listing {0} threw an exception of type {1}.", input, - exception.GetType())); } } finally @@ -173,7 +176,7 @@ private static string[] GetArguments() } else { - args = userArguments.Split(new[] {' '}); + args = userArguments.Split(new[] { ' ' }); } return args; @@ -181,7 +184,7 @@ private static string[] GetArguments() private static string ParseListingName(string listing) { - var appendices = new List {"A", "B", "C", "D"}; + var appendices = new List { "A", "B", "C", "D" }; string chapterName = ""; diff --git a/src/Versioning.targets b/src/Versioning.targets deleted file mode 100644 index 710d30ada..000000000 --- a/src/Versioning.targets +++ /dev/null @@ -1,8 +0,0 @@ - - - - Mark Michaelis - Addison Wesley - Copyright © Addison Wesley 2017 - - \ No newline at end of file