diff --git a/exclusion.dic b/exclusion.dic index 05736362a..e772b28b8 100644 --- a/exclusion.dic +++ b/exclusion.dic @@ -61,4 +61,5 @@ Parksdale Monteray inigo Machava -Uncompress \ No newline at end of file +Uncompress +expialidocious diff --git a/src/Chapter17.Tests/Listing17.07A.IteratingOverSortedDictionaryWithForeach.Tests.cs b/src/Chapter17.Tests/Listing17.07A.IteratingOverSortedDictionaryWithForeach.Tests.cs deleted file mode 100644 index 78e79b1a8..000000000 --- a/src/Chapter17.Tests/Listing17.07A.IteratingOverSortedDictionaryWithForeach.Tests.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_07a.Tests; - -[TestClass] -public class ProgramTests -{ - [TestMethod] - public void SortedDictionaryOutputOrder() - { - string expected = string.Join( - System.Environment.NewLine, - "Error","Information", "Verbose", "Warning"); - - IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, - () => - { - Program.Main(); - }); - } -} \ No newline at end of file diff --git a/src/Chapter17.Tests/Listing17.09.SlicingWithSpan.Tests.cs b/src/Chapter17.Tests/Listing17.09.SlicingWithSpan.Tests.cs new file mode 100644 index 000000000..0a5c4d742 --- /dev/null +++ b/src/Chapter17.Tests/Listing17.09.SlicingWithSpan.Tests.cs @@ -0,0 +1,17 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_09.Tests; + +[TestClass] +public class ProgramTests +{ + [TestMethod] + public void DictionaryInitialization() + { + IntelliTect.TestTools.Console.ConsoleAssert.Execute(null, + () => + { + Program.Main(); + }); + } +} diff --git a/src/Chapter17.Tests/Listing17.11.DefiningAnIndexOperatorWithVariableParameters.Tests.cs b/src/Chapter17.Tests/Listing17.12.DefiningAnIndexOperatorWithVariableParameters.Tests.cs similarity index 83% rename from src/Chapter17.Tests/Listing17.11.DefiningAnIndexOperatorWithVariableParameters.Tests.cs rename to src/Chapter17.Tests/Listing17.12.DefiningAnIndexOperatorWithVariableParameters.Tests.cs index 2c8946746..ab8c75ac5 100644 --- a/src/Chapter17.Tests/Listing17.11.DefiningAnIndexOperatorWithVariableParameters.Tests.cs +++ b/src/Chapter17.Tests/Listing17.12.DefiningAnIndexOperatorWithVariableParameters.Tests.cs @@ -1,6 +1,6 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_11.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_12.Tests; [TestClass] public class ProgramTests @@ -15,4 +15,4 @@ public void IteratingABinaryTree() IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, Program.Main); } -} \ No newline at end of file +} diff --git a/src/Chapter17.Tests/Listing17.13.Tests.cs b/src/Chapter17.Tests/Listing17.14.YieldingTheCSharpKeywordsSequentially.Tests.cs similarity index 84% rename from src/Chapter17.Tests/Listing17.13.Tests.cs rename to src/Chapter17.Tests/Listing17.14.YieldingTheCSharpKeywordsSequentially.Tests.cs index 29f263bdf..28711d9ad 100644 --- a/src/Chapter17.Tests/Listing17.13.Tests.cs +++ b/src/Chapter17.Tests/Listing17.14.YieldingTheCSharpKeywordsSequentially.Tests.cs @@ -1,6 +1,6 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_13.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_14.Tests; [TestClass] public class ProgramTests @@ -28,4 +28,4 @@ public void MainTest() IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); } -} \ No newline at end of file +} diff --git a/src/Chapter17.Tests/Listing17.15.Tests.cs b/src/Chapter17.Tests/Listing17.16.UsingPair.GetEnumeratorViaForeach.Tests.cs similarity index 81% rename from src/Chapter17.Tests/Listing17.15.Tests.cs rename to src/Chapter17.Tests/Listing17.16.UsingPair.GetEnumeratorViaForeach.Tests.cs index b88c1c848..605510956 100644 --- a/src/Chapter17.Tests/Listing17.15.Tests.cs +++ b/src/Chapter17.Tests/Listing17.16.UsingPair.GetEnumeratorViaForeach.Tests.cs @@ -1,6 +1,6 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_15.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_16.Tests; [TestClass] public class ProgramTests @@ -14,4 +14,4 @@ public void MainTest() IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); } -} \ No newline at end of file +} diff --git a/src/Chapter17.Tests/Listing17.17.UsingForeachWithBinaryTree.Tests.cs b/src/Chapter17.Tests/Listing17.18.UsingForeachWithBinaryTree.Tests.cs similarity index 87% rename from src/Chapter17.Tests/Listing17.17.UsingForeachWithBinaryTree.Tests.cs rename to src/Chapter17.Tests/Listing17.18.UsingForeachWithBinaryTree.Tests.cs index fe73a6b60..d7719f8ca 100644 --- a/src/Chapter17.Tests/Listing17.17.UsingForeachWithBinaryTree.Tests.cs +++ b/src/Chapter17.Tests/Listing17.18.UsingForeachWithBinaryTree.Tests.cs @@ -1,6 +1,6 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_17.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_18.Tests; [TestClass] public class ProgramTests @@ -20,4 +20,4 @@ John Francis Fitzgerald IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, () => Program.Main()); } -} \ No newline at end of file +} diff --git a/src/Chapter17.Tests/Listing17.20.Tests.cs b/src/Chapter17.Tests/Listing17.21.UsingYieldReturnInAMethodThatReturnsIEnumberable.Tests.cs similarity index 81% rename from src/Chapter17.Tests/Listing17.20.Tests.cs rename to src/Chapter17.Tests/Listing17.21.UsingYieldReturnInAMethodThatReturnsIEnumberable.Tests.cs index ee989d00b..21f12b87c 100644 --- a/src/Chapter17.Tests/Listing17.20.Tests.cs +++ b/src/Chapter17.Tests/Listing17.21.UsingYieldReturnInAMethodThatReturnsIEnumberable.Tests.cs @@ -1,6 +1,6 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_20.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_21.Tests; [TestClass] public class ProgramTests @@ -14,4 +14,4 @@ public void MainTest() IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); } -} \ No newline at end of file +} diff --git a/src/Chapter17/Chapter17.csproj b/src/Chapter17/Chapter17.csproj index 02b512938..968412992 100644 --- a/src/Chapter17/Chapter17.csproj +++ b/src/Chapter17/Chapter17.csproj @@ -4,10 +4,13 @@ - + - + + + + Program.cs diff --git a/src/Chapter17/Listing17.09.SlicingWithSpan.cs b/src/Chapter17/Listing17.09.SlicingWithSpan.cs new file mode 100644 index 000000000..d57ecf88a --- /dev/null +++ b/src/Chapter17/Listing17.09.SlicingWithSpan.cs @@ -0,0 +1,51 @@ +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_09; + +using System.Diagnostics; +using System.Runtime.CompilerServices; + +public class Program +{ + public static void Main() + { + #region INCLUDE + string[] languages = new [] { + "C#", "COBOL", "Java", + "C++", "TypeScript", "Python",}; + + // Create a Span from the arrays first 3 elements. + Span languageSpan = languages.AsSpan(0, 2); + languages[0] = "R"; + Assert(languages[0] == languageSpan[0]); + Assert("R" == languageSpan[0]); + languageSpan[0] = "Lisp"; + Assert(languages[0] == languageSpan[0]); + Assert("Lisp" == languages[0]); + + int[] numbers = languages.Select(item => item.Length).ToArray(); + // Create a Span from the arrays first 3 elements. + Span numbersSpan = numbers.AsSpan(0, 2); + Assert(numbers[1] == numbersSpan[1]); + numbersSpan[1] = 42; + Assert(numbers[1] == numbersSpan[1]); + Assert(42 == numbers[1]); + + const string bigWord = "supercalifragilisticexpialidocious"; + // Create a Span from a suffix portion of the word. + #if NET8_0_OR_GREATER + ReadOnlySpan expialidocious = bigWord.AsSpan(20..); + #else // NET8_0_OR_GREATER + ReadOnlySpan expialidocious = bigWord.AsSpan(20, 14); + #endif // NET8_0_OR_GREATER + Assert(expialidocious.ToString() == "expialidocious"); +#endregion INCLUDE + } + + static void Assert(bool condition, + [CallerArgumentExpression(nameof(condition))]string expression = null!) + { + if (!condition) + { + throw new Exception($"Assertion failed: {expression}"); + } + } +} diff --git a/src/Chapter17/Listing17.09.DefiningAnIndexer.cs b/src/Chapter17/Listing17.10.DefiningAnIndexer.cs similarity index 99% rename from src/Chapter17/Listing17.09.DefiningAnIndexer.cs rename to src/Chapter17/Listing17.10.DefiningAnIndexer.cs index 2aa770956..ad6a3671f 100644 --- a/src/Chapter17/Listing17.09.DefiningAnIndexer.cs +++ b/src/Chapter17/Listing17.10.DefiningAnIndexer.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_09; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_10; using System; diff --git a/src/Chapter17/Listing17.10.ChangingTheIndexersDefaultName.cs b/src/Chapter17/Listing17.11.ChangingTheIndexersDefaultName.cs similarity index 99% rename from src/Chapter17/Listing17.10.ChangingTheIndexersDefaultName.cs rename to src/Chapter17/Listing17.11.ChangingTheIndexersDefaultName.cs index 2cd5b9488..3bddc57a2 100644 --- a/src/Chapter17/Listing17.10.ChangingTheIndexersDefaultName.cs +++ b/src/Chapter17/Listing17.11.ChangingTheIndexersDefaultName.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_10; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_11; using System; diff --git a/src/Chapter17/Listing17.11.DefiningAnIndexOperatorWithVariableParameters.cs b/src/Chapter17/Listing17.12.DefiningAnIndexOperatorWithVariableParameters.cs similarity index 99% rename from src/Chapter17/Listing17.11.DefiningAnIndexOperatorWithVariableParameters.cs rename to src/Chapter17/Listing17.12.DefiningAnIndexOperatorWithVariableParameters.cs index 89487ea82..4d6f03634 100644 --- a/src/Chapter17/Listing17.11.DefiningAnIndexOperatorWithVariableParameters.cs +++ b/src/Chapter17/Listing17.12.DefiningAnIndexOperatorWithVariableParameters.cs @@ -1,6 +1,6 @@ using AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_10; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_11; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_12; #region INCLUDE using System; diff --git a/src/Chapter17/Listing17.12.IteratorInterfacesPattern.cs b/src/Chapter17/Listing17.13.IteratorInterfacesPattern.cs similarity index 99% rename from src/Chapter17/Listing17.12.IteratorInterfacesPattern.cs rename to src/Chapter17/Listing17.13.IteratorInterfacesPattern.cs index 0acef63a8..e6dd752c9 100644 --- a/src/Chapter17/Listing17.12.IteratorInterfacesPattern.cs +++ b/src/Chapter17/Listing17.13.IteratorInterfacesPattern.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_12; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_13; #region INCLUDE using System.Collections; diff --git a/src/Chapter17/Listing17.13.YieldingTheCSharpKeywordsSequentially.cs b/src/Chapter17/Listing17.14.YieldingTheCSharpKeywordsSequentially.cs similarity index 99% rename from src/Chapter17/Listing17.13.YieldingTheCSharpKeywordsSequentially.cs rename to src/Chapter17/Listing17.14.YieldingTheCSharpKeywordsSequentially.cs index 0bd528249..779ad9be5 100644 --- a/src/Chapter17/Listing17.13.YieldingTheCSharpKeywordsSequentially.cs +++ b/src/Chapter17/Listing17.14.YieldingTheCSharpKeywordsSequentially.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_13; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_14; #region INCLUDE using System; diff --git a/src/Chapter17/Listing17.14.UsingYieldToImplementBinaryTree.cs b/src/Chapter17/Listing17.15.UsingYieldToImplementBinaryTree.cs similarity index 99% rename from src/Chapter17/Listing17.14.UsingYieldToImplementBinaryTree.cs rename to src/Chapter17/Listing17.15.UsingYieldToImplementBinaryTree.cs index e3201c08c..3ed3c1b1d 100644 --- a/src/Chapter17/Listing17.14.UsingYieldToImplementBinaryTree.cs +++ b/src/Chapter17/Listing17.15.UsingYieldToImplementBinaryTree.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_14; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_15; using System; using Listing17_10; diff --git a/src/Chapter17/Listing17.15.UsingPair.GetEnumeratorViaForeach.cs b/src/Chapter17/Listing17.16.UsingPair.GetEnumeratorViaForeach.cs similarity index 92% rename from src/Chapter17/Listing17.15.UsingPair.GetEnumeratorViaForeach.cs rename to src/Chapter17/Listing17.16.UsingPair.GetEnumeratorViaForeach.cs index f743547af..89b46caf9 100644 --- a/src/Chapter17/Listing17.15.UsingPair.GetEnumeratorViaForeach.cs +++ b/src/Chapter17/Listing17.16.UsingPair.GetEnumeratorViaForeach.cs @@ -1,7 +1,7 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_15; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_16; using System; -using Listing17_14; +using Listing17_15; public class Program { diff --git a/src/Chapter17/Listing17.16.PlacingYieldReturnStatementsWithinALoop.cs b/src/Chapter17/Listing17.17.PlacingYieldReturnStatementsWithinALoop.cs similarity index 97% rename from src/Chapter17/Listing17.16.PlacingYieldReturnStatementsWithinALoop.cs rename to src/Chapter17/Listing17.17.PlacingYieldReturnStatementsWithinALoop.cs index 825d9842d..1b75abcad 100644 --- a/src/Chapter17/Listing17.16.PlacingYieldReturnStatementsWithinALoop.cs +++ b/src/Chapter17/Listing17.17.PlacingYieldReturnStatementsWithinALoop.cs @@ -1,7 +1,7 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_16; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_17; using System.Collections.Generic; -using Listing17_14; +using Listing17_15; #region INCLUDE public class BinaryTree : IEnumerable diff --git a/src/Chapter17/Listing17.17.UsingForeachWithBinaryTree.cs b/src/Chapter17/Listing17.18.UsingForeachWithBinaryTree.cs similarity index 96% rename from src/Chapter17/Listing17.17.UsingForeachWithBinaryTree.cs rename to src/Chapter17/Listing17.18.UsingForeachWithBinaryTree.cs index ec7a6a345..542c58d1e 100644 --- a/src/Chapter17/Listing17.17.UsingForeachWithBinaryTree.cs +++ b/src/Chapter17/Listing17.18.UsingForeachWithBinaryTree.cs @@ -1,8 +1,8 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_17; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_18; using System; -using Listing17_14; -using Listing17_16; +using Listing17_15; +using Listing17_17; public class Program { @@ -38,4 +38,4 @@ public static void Main() #endregion HIGHLIGHT #endregion INCLUDE } -} \ No newline at end of file +} diff --git a/src/Chapter17/Listing17.18.EscapingIterationViaYieldBreak.cs b/src/Chapter17/Listing17.19.EscapingIterationViaYieldBreak.cs similarity index 99% rename from src/Chapter17/Listing17.18.EscapingIterationViaYieldBreak.cs rename to src/Chapter17/Listing17.19.EscapingIterationViaYieldBreak.cs index 2f6aab0c0..179996900 100644 --- a/src/Chapter17/Listing17.18.EscapingIterationViaYieldBreak.cs +++ b/src/Chapter17/Listing17.19.EscapingIterationViaYieldBreak.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_18; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_19; using System; using Listing17_10; diff --git a/src/Chapter17/Listing17.19.CSharpEquivalentOfCompilerGeneratedCodeForIterators.cs b/src/Chapter17/Listing17.20.CSharpEquivalentOfCompilerGeneratedCodeForIterators.cs similarity index 99% rename from src/Chapter17/Listing17.19.CSharpEquivalentOfCompilerGeneratedCodeForIterators.cs rename to src/Chapter17/Listing17.20.CSharpEquivalentOfCompilerGeneratedCodeForIterators.cs index 675b9fad2..3998ecf93 100644 --- a/src/Chapter17/Listing17.19.CSharpEquivalentOfCompilerGeneratedCodeForIterators.cs +++ b/src/Chapter17/Listing17.20.CSharpEquivalentOfCompilerGeneratedCodeForIterators.cs @@ -1,10 +1,10 @@ -using AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_10; +using AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_11; #region INCLUDE using System; using System.Collections; using System.Collections.Generic; #region EXCLUDE -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_19 +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_20 { #endregion EXCLUDE [NullableContext(1)] diff --git a/src/Chapter17/Listing17.20.UsingYieldReturnInAMethodThatReturnsIEnumberable.cs b/src/Chapter17/Listing17.21.UsingYieldReturnInAMethodThatReturnsIEnumberable.cs similarity index 99% rename from src/Chapter17/Listing17.20.UsingYieldReturnInAMethodThatReturnsIEnumberable.cs rename to src/Chapter17/Listing17.21.UsingYieldReturnInAMethodThatReturnsIEnumberable.cs index a8bbe3a3d..aee2a3803 100644 --- a/src/Chapter17/Listing17.20.UsingYieldReturnInAMethodThatReturnsIEnumberable.cs +++ b/src/Chapter17/Listing17.21.UsingYieldReturnInAMethodThatReturnsIEnumberable.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_20; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_21; using System; using Listing17_10;