diff --git a/src/Chapter18.Tests/Listing18.17.RetrievingASpecificAttributeAndCheckingItsInitialization.Tests.cs b/src/Chapter18.Tests/Listing18.16.RetrievingASpecificAttributeAndCheckingItsInitialization.Tests.cs similarity index 95% rename from src/Chapter18.Tests/Listing18.17.RetrievingASpecificAttributeAndCheckingItsInitialization.Tests.cs rename to src/Chapter18.Tests/Listing18.16.RetrievingASpecificAttributeAndCheckingItsInitialization.Tests.cs index 385d14948..8b36398f2 100644 --- a/src/Chapter18.Tests/Listing18.17.RetrievingASpecificAttributeAndCheckingItsInitialization.Tests.cs +++ b/src/Chapter18.Tests/Listing18.16.RetrievingASpecificAttributeAndCheckingItsInitialization.Tests.cs @@ -1,6 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_17.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_16.Tests; [TestClass] public class ProgramTests diff --git a/src/Chapter18.Tests/Listing18.25.UsingConditionalAttributeToEliminateACall.Tests.cs b/src/Chapter18.Tests/Listing18.24.UsingConditionalAttributeToEliminateACall.Tests.cs similarity index 96% rename from src/Chapter18.Tests/Listing18.25.UsingConditionalAttributeToEliminateACall.Tests.cs rename to src/Chapter18.Tests/Listing18.24.UsingConditionalAttributeToEliminateACall.Tests.cs index 1fe007a7f..433efe51c 100644 --- a/src/Chapter18.Tests/Listing18.25.UsingConditionalAttributeToEliminateACall.Tests.cs +++ b/src/Chapter18.Tests/Listing18.24.UsingConditionalAttributeToEliminateACall.Tests.cs @@ -1,6 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_25.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_24.Tests; [TestClass] public class ProgramTests diff --git a/src/Chapter18.Tests/Listing18.27.GenericException.Tests.cs b/src/Chapter18.Tests/Listing18.26.GenericException.Tests.cs similarity index 97% rename from src/Chapter18.Tests/Listing18.27.GenericException.Tests.cs rename to src/Chapter18.Tests/Listing18.26.GenericException.Tests.cs index b4f07bb66..902709e4c 100644 --- a/src/Chapter18.Tests/Listing18.27.GenericException.Tests.cs +++ b/src/Chapter18.Tests/Listing18.26.GenericException.Tests.cs @@ -1,6 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_27.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_26.Tests; #if NET7_0_OR_GREATER [TestClass] diff --git a/src/Chapter18.Tests/Listing18.28.CallerArgumentExpression.Tests.cs b/src/Chapter18.Tests/Listing18.27.CallerArgumentExpression.Tests.cs similarity index 56% rename from src/Chapter18.Tests/Listing18.28.CallerArgumentExpression.Tests.cs rename to src/Chapter18.Tests/Listing18.27.CallerArgumentExpression.Tests.cs index 9eb8b2c55..6901536f3 100644 --- a/src/Chapter18.Tests/Listing18.28.CallerArgumentExpression.Tests.cs +++ b/src/Chapter18.Tests/Listing18.27.CallerArgumentExpression.Tests.cs @@ -1,6 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_28.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_27.Tests; #if NET7_0_OR_GREATER [TestClass] @@ -27,29 +27,6 @@ public void VerifyExpectedExceptionMessage() } } - [TestMethod] - public void Method() - { - try - { - SampleTests.Method(); - } - catch (InvalidOperationException exception) - { - Assert.IsTrue( - exception.Message.Contains("'() => { }'") && - exception.Message.Contains("'Method'") && - exception.Message.Contains("'./FileName.cs'")); - // The expected exception, System.DivideByZeroException, - // was not thrown by the expression, 'Method' in the method, './FileName.cs', and file 'C:\Git\EssentialCSharp\src\Chapter18\Listing18.25b.CallerArgumentExpression.cs'. - } - } - - private object PassingMethodNameAndFileName() - { - throw new NotImplementedException(); - } - [TestMethod] [ExpectedException(typeof(InvalidOperationException))] public void ExpectedExceptionIsNotThrown() diff --git a/src/Chapter18.Tests/Listing18.28a.Tests.cs b/src/Chapter18.Tests/Listing18.28a.Tests.cs new file mode 100644 index 000000000..f78c728e8 --- /dev/null +++ b/src/Chapter18.Tests/Listing18.28a.Tests.cs @@ -0,0 +1,27 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_28.Tests; + +#if NET7_0_OR_GREATER +[TestClass] +public class GenericExceptionTests +{ + [TestMethod] + public void Method() + { + try + { + Program.Main(); + } + catch (InvalidOperationException exception) + { + Assert.IsTrue( + exception.Message.Contains("'() => { }'") && + exception.Message.Contains("'Method'") && + exception.Message.Contains("'./FileName.cs'")); + // The expected exception, System.DivideByZeroException, + // was not thrown by the expression, 'Method' in the method, './FileName.cs', and file 'C:\Git\EssentialCSharp\src\Chapter18\Listing18.25b.CallerArgumentExpression.cs'. + } + } +} +#endif // NET7_0_OR_GREATER diff --git a/src/Chapter18/Listing18.13.csprojMockFileForResequencingListings.Placeholder.cs b/src/Chapter18/Listing18.12.csprojMockFileForResequencingListings.Placeholder.cs similarity index 100% rename from src/Chapter18/Listing18.13.csprojMockFileForResequencingListings.Placeholder.cs rename to src/Chapter18/Listing18.12.csprojMockFileForResequencingListings.Placeholder.cs diff --git a/src/Chapter18/Listing18.14.DefiningACustomAttribute.cs b/src/Chapter18/Listing18.13.DefiningACustomAttribute.cs similarity index 94% rename from src/Chapter18/Listing18.14.DefiningACustomAttribute.cs rename to src/Chapter18/Listing18.13.DefiningACustomAttribute.cs index b2054f8f6..1c8874a4a 100644 --- a/src/Chapter18/Listing18.14.DefiningACustomAttribute.cs +++ b/src/Chapter18/Listing18.13.DefiningACustomAttribute.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_14; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_13; #region INCLUDE public class CommandLineSwitchRequiredAttribute : Attribute diff --git a/src/Chapter18/Listing18.15.RetrievingACustomAttribute.cs b/src/Chapter18/Listing18.14.RetrievingACustomAttribute.cs similarity index 98% rename from src/Chapter18/Listing18.15.RetrievingACustomAttribute.cs rename to src/Chapter18/Listing18.14.RetrievingACustomAttribute.cs index cb75dec97..de95efd07 100644 --- a/src/Chapter18/Listing18.15.RetrievingACustomAttribute.cs +++ b/src/Chapter18/Listing18.14.RetrievingACustomAttribute.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_15; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_14; #region INCLUDE using System.Reflection; diff --git a/src/Chapter18/Listing18.16.ProvidingAnAttributeConstructor.cs b/src/Chapter18/Listing18.15.ProvidingAnAttributeConstructor.cs similarity index 98% rename from src/Chapter18/Listing18.16.ProvidingAnAttributeConstructor.cs rename to src/Chapter18/Listing18.15.ProvidingAnAttributeConstructor.cs index 6999f2219..4e47f2541 100644 --- a/src/Chapter18/Listing18.16.ProvidingAnAttributeConstructor.cs +++ b/src/Chapter18/Listing18.15.ProvidingAnAttributeConstructor.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_16; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_15; #region INCLUDE public class CommandLineSwitchAliasAttribute : Attribute diff --git a/src/Chapter18/Listing18.17.RetrievingASpecificAttributeAndCheckingItsInitialization.cs b/src/Chapter18/Listing18.16.RetrievingASpecificAttributeAndCheckingItsInitialization.cs similarity index 97% rename from src/Chapter18/Listing18.17.RetrievingASpecificAttributeAndCheckingItsInitialization.cs rename to src/Chapter18/Listing18.16.RetrievingASpecificAttributeAndCheckingItsInitialization.cs index 350d0d664..7f2cfcd58 100644 --- a/src/Chapter18/Listing18.17.RetrievingASpecificAttributeAndCheckingItsInitialization.cs +++ b/src/Chapter18/Listing18.16.RetrievingASpecificAttributeAndCheckingItsInitialization.cs @@ -1,6 +1,6 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_17; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_16; -using AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_16; +using AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_15; using System.Reflection; public class Program diff --git a/src/Chapter18/Listing18.18.RetrievingCustomAttributeInstances.cs b/src/Chapter18/Listing18.17.RetrievingCustomAttributeInstances.cs similarity index 99% rename from src/Chapter18/Listing18.18.RetrievingCustomAttributeInstances.cs rename to src/Chapter18/Listing18.17.RetrievingCustomAttributeInstances.cs index 517748baf..1d6d80569 100644 --- a/src/Chapter18/Listing18.18.RetrievingCustomAttributeInstances.cs +++ b/src/Chapter18/Listing18.17.RetrievingCustomAttributeInstances.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_18; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_17; #region INCLUDE using System.Reflection; diff --git a/src/Chapter18/Listing18.19.UpdatingCommandLineHandler.TryParseToHandleAliases.cs b/src/Chapter18/Listing18.18.UpdatingCommandLineHandler.TryParseToHandleAliases.cs similarity index 99% rename from src/Chapter18/Listing18.19.UpdatingCommandLineHandler.TryParseToHandleAliases.cs rename to src/Chapter18/Listing18.18.UpdatingCommandLineHandler.TryParseToHandleAliases.cs index 1a3f1c47c..9f345bcd8 100644 --- a/src/Chapter18/Listing18.19.UpdatingCommandLineHandler.TryParseToHandleAliases.cs +++ b/src/Chapter18/Listing18.18.UpdatingCommandLineHandler.TryParseToHandleAliases.cs @@ -1,6 +1,6 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_19; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_18; -using Listing18_18; +using Listing18_17; #region INCLUDE using System.Reflection; using System.Collections.Generic; diff --git a/src/Chapter18/Listing18.20.RestrictingTheConstructsAnAttributeCanDecorate.cs b/src/Chapter18/Listing18.19.RestrictingTheConstructsAnAttributeCanDecorate.cs similarity index 95% rename from src/Chapter18/Listing18.20.RestrictingTheConstructsAnAttributeCanDecorate.cs rename to src/Chapter18/Listing18.19.RestrictingTheConstructsAnAttributeCanDecorate.cs index a5d6d6c30..d43846bf5 100644 --- a/src/Chapter18/Listing18.20.RestrictingTheConstructsAnAttributeCanDecorate.cs +++ b/src/Chapter18/Listing18.19.RestrictingTheConstructsAnAttributeCanDecorate.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_20; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_19; #region INCLUDE [AttributeUsage(AttributeTargets.Property)] diff --git a/src/Chapter18/Listing18.21.AttributeUsageAttributeRestrictingWhereToApplyAnAttribute.cs b/src/Chapter18/Listing18.20.AttributeUsageAttributeRestrictingWhereToApplyAnAttribute.cs similarity index 96% rename from src/Chapter18/Listing18.21.AttributeUsageAttributeRestrictingWhereToApplyAnAttribute.cs rename to src/Chapter18/Listing18.20.AttributeUsageAttributeRestrictingWhereToApplyAnAttribute.cs index dd6978287..606196aa4 100644 --- a/src/Chapter18/Listing18.21.AttributeUsageAttributeRestrictingWhereToApplyAnAttribute.cs +++ b/src/Chapter18/Listing18.20.AttributeUsageAttributeRestrictingWhereToApplyAnAttribute.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_21; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_20; // Will not compile if uncommented /* diff --git a/src/Chapter18/Listing18.22.LimitingAnAttributesUsageWithAttributeUsageAttribute.cs b/src/Chapter18/Listing18.21.LimitingAnAttributesUsageWithAttributeUsageAttribute.cs similarity index 97% rename from src/Chapter18/Listing18.22.LimitingAnAttributesUsageWithAttributeUsageAttribute.cs rename to src/Chapter18/Listing18.21.LimitingAnAttributesUsageWithAttributeUsageAttribute.cs index 3676b0826..e050de1f8 100644 --- a/src/Chapter18/Listing18.22.LimitingAnAttributesUsageWithAttributeUsageAttribute.cs +++ b/src/Chapter18/Listing18.21.LimitingAnAttributesUsageWithAttributeUsageAttribute.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_22; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_21; #region INCLUDE // Restrict the attribute to properties and methods diff --git a/src/Chapter18/Listing18.23.UsingANamedParameter.cs b/src/Chapter18/Listing18.22.UsingANamedParameter.cs similarity index 95% rename from src/Chapter18/Listing18.23.UsingANamedParameter.cs rename to src/Chapter18/Listing18.22.UsingANamedParameter.cs index c035f7ee0..4e6997b34 100644 --- a/src/Chapter18/Listing18.23.UsingANamedParameter.cs +++ b/src/Chapter18/Listing18.22.UsingANamedParameter.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_23; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_22; #region INCLUDE [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)] diff --git a/src/Chapter18/Listing18.24.UsingFlagsAttribute.cs b/src/Chapter18/Listing18.23.UsingFlagsAttribute.cs similarity index 98% rename from src/Chapter18/Listing18.24.UsingFlagsAttribute.cs rename to src/Chapter18/Listing18.23.UsingFlagsAttribute.cs index 137200e80..15afe8c2d 100644 --- a/src/Chapter18/Listing18.24.UsingFlagsAttribute.cs +++ b/src/Chapter18/Listing18.23.UsingFlagsAttribute.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_24; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_23; #region INCLUDE /* diff --git a/src/Chapter18/Listing18.25.UsingConditionalAttributeToEliminateACall.cs b/src/Chapter18/Listing18.24.UsingConditionalAttributeToEliminateACall.cs similarity index 98% rename from src/Chapter18/Listing18.25.UsingConditionalAttributeToEliminateACall.cs rename to src/Chapter18/Listing18.24.UsingConditionalAttributeToEliminateACall.cs index daba8cc60..0cf0353d8 100644 --- a/src/Chapter18/Listing18.25.UsingConditionalAttributeToEliminateACall.cs +++ b/src/Chapter18/Listing18.24.UsingConditionalAttributeToEliminateACall.cs @@ -1,7 +1,7 @@ #region INCLUDE #define CONDITION_A #region EXCLUDE -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_25; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_24; #endregion EXCLUDE using System.Diagnostics; diff --git a/src/Chapter18/Listing18.26.UsingObsoleteAttribute.cs b/src/Chapter18/Listing18.25.UsingObsoleteAttribute.cs similarity index 96% rename from src/Chapter18/Listing18.26.UsingObsoleteAttribute.cs rename to src/Chapter18/Listing18.25.UsingObsoleteAttribute.cs index 2f8ca5414..8eecc5962 100644 --- a/src/Chapter18/Listing18.26.UsingObsoleteAttribute.cs +++ b/src/Chapter18/Listing18.25.UsingObsoleteAttribute.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_26; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_25; #region INCLUDE public class Program diff --git a/src/Chapter18/Listing18.27.GenericException.cs b/src/Chapter18/Listing18.26.GenericException.cs similarity index 98% rename from src/Chapter18/Listing18.27.GenericException.cs rename to src/Chapter18/Listing18.26.GenericException.cs index 0eafbe330..7d29d06c8 100644 --- a/src/Chapter18/Listing18.27.GenericException.cs +++ b/src/Chapter18/Listing18.26.GenericException.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_27; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_26; #if NET7_0_OR_GREATER #region INCLUDE diff --git a/src/Chapter18/Listing18.28.CallerArgumentExpression.cs b/src/Chapter18/Listing18.27.CallerArgumentExpression.cs similarity index 90% rename from src/Chapter18/Listing18.28.CallerArgumentExpression.cs rename to src/Chapter18/Listing18.27.CallerArgumentExpression.cs index 8391d837f..86ce31dde 100644 --- a/src/Chapter18/Listing18.28.CallerArgumentExpression.cs +++ b/src/Chapter18/Listing18.27.CallerArgumentExpression.cs @@ -1,6 +1,6 @@ using System.Runtime.CompilerServices; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_28; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_27; #if NET7_0_OR_GREATER #region INCLUDE @@ -13,12 +13,6 @@ public static void ThrowArgumentNullExceptionTest() { var result = 1/"".Length; } - -public static void Method() -{ - ExpectedException.AssertExceptionThrown( - () => throw new DivideByZeroException()); -} } [AttributeUsage(AttributeTargets.Method)] diff --git a/src/Chapter18/Listing18.28.InvokingCallerAttributesMethod.cs b/src/Chapter18/Listing18.28.InvokingCallerAttributesMethod.cs new file mode 100644 index 000000000..3e2c627ac --- /dev/null +++ b/src/Chapter18/Listing18.28.InvokingCallerAttributesMethod.cs @@ -0,0 +1,16 @@ +using AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_27; + +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_28; + +#if NET7_0_OR_GREATER +public class Program +{ + public static void Main() + { + #region INCLUDE + ExpectedException.AssertExceptionThrown( + () => throw new DivideByZeroException()); + #endregion INCLUDE + } +} +#endif // NET7_0_OR_GREATER