From b89f9e2e10eee62950d1f97c00c0249a8bc27da8 Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Mon, 11 Sep 2023 09:03:08 +0100 Subject: [PATCH 1/7] Added primary constructor example. --- ...Listing06.26.DefiningAConstructor.Tests.cs | 2 +- ...isting06.26.DefiningAPrimaryConstructor.cs | 66 +++++++++++++++++++ .../Listing06.27.CallingAConstructor.cs | 2 +- ... => Listing06.27a.DefiningAConstructor.cs} | 5 +- ....28.DefaultConstructorNoLongerAvailable.cs | 2 +- ...Listing06.30.CallingAnObjectInitializer.cs | 2 +- 6 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 src/Chapter06/Listing06.26.DefiningAPrimaryConstructor.cs rename src/Chapter06/{Listing06.26.DefiningAConstructor.cs => Listing06.27a.DefiningAConstructor.cs} (90%) diff --git a/src/Chapter06.Tests/Listing06.26.DefiningAConstructor.Tests.cs b/src/Chapter06.Tests/Listing06.26.DefiningAConstructor.Tests.cs index 964f8d77c..dee18be1d 100644 --- a/src/Chapter06.Tests/Listing06.26.DefiningAConstructor.Tests.cs +++ b/src/Chapter06.Tests/Listing06.26.DefiningAConstructor.Tests.cs @@ -1,6 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_26.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_27a.Tests; [TestClass] public class ProgramTests diff --git a/src/Chapter06/Listing06.26.DefiningAPrimaryConstructor.cs b/src/Chapter06/Listing06.26.DefiningAPrimaryConstructor.cs new file mode 100644 index 000000000..767dc1f8c --- /dev/null +++ b/src/Chapter06/Listing06.26.DefiningAPrimaryConstructor.cs @@ -0,0 +1,66 @@ +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_26; + +#if NET8_0_OR_GREATER +public class Program +{ + public static void Main() + { + Employee employee; + employee = new("Inigo", "Montoya"); + employee.Salary = "Too Little"; + + System.Console.WriteLine( + "{0} {1}: {2}", + employee.FirstName, + employee.LastName, + employee.Salary); + } +} + +#region INCLUDE + #region HIGHLIGHT + // Employee constructor +public class Employee(string firstName, string lastName) +{ + public string FirstName { get; set; } = firstName; + public string LastName { get; set; } = lastName; + #endregion HIGHLIGHT + public string? Salary { get; set; } = "Not Enough"; + + #region EXCLUDE + public string? Title { get; set; } + public Employee? Manager { get; set; } + + // Name property + public string Name + { + get + { + return FirstName + " " + LastName; + } + set + { + // Split the assigned value into + // first and last names + string[] names; + names = value.Split(new char[] { ' ' }); + if(names.Length == 2) + { + FirstName = names[0]; + LastName = names[1]; + } + else + { + // Throw an exception if the full + // name was not assigned + throw new System.ArgumentException( + string.Format( + $"Assigned value '{ value }' is invalid", + nameof(value))); + } + } + } + #endregion EXCLUDE +} +#endregion INCLUDE +#endif // NET8_0_OR_GREATER \ No newline at end of file diff --git a/src/Chapter06/Listing06.27.CallingAConstructor.cs b/src/Chapter06/Listing06.27.CallingAConstructor.cs index 7ed879528..b990f570b 100644 --- a/src/Chapter06/Listing06.27.CallingAConstructor.cs +++ b/src/Chapter06/Listing06.27.CallingAConstructor.cs @@ -1,6 +1,6 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_27; -using Listing06_26; +using Listing06_27a; #region INCLUDE public class Program diff --git a/src/Chapter06/Listing06.26.DefiningAConstructor.cs b/src/Chapter06/Listing06.27a.DefiningAConstructor.cs similarity index 90% rename from src/Chapter06/Listing06.26.DefiningAConstructor.cs rename to src/Chapter06/Listing06.27a.DefiningAConstructor.cs index 693a37052..48939b9e8 100644 --- a/src/Chapter06/Listing06.26.DefiningAConstructor.cs +++ b/src/Chapter06/Listing06.27a.DefiningAConstructor.cs @@ -1,7 +1,4 @@ -// Disabled pending introductin to object initializers -#pragma warning disable IDE0017 - -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_26; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_27a; public class Program { diff --git a/src/Chapter06/Listing06.28.DefaultConstructorNoLongerAvailable.cs b/src/Chapter06/Listing06.28.DefaultConstructorNoLongerAvailable.cs index 41962bc91..fccb0eec1 100644 --- a/src/Chapter06/Listing06.28.DefaultConstructorNoLongerAvailable.cs +++ b/src/Chapter06/Listing06.28.DefaultConstructorNoLongerAvailable.cs @@ -3,7 +3,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_28; -using Listing06_26; +using Listing06_27a; #region INCLUDE public class Program diff --git a/src/Chapter06/Listing06.30.CallingAnObjectInitializer.cs b/src/Chapter06/Listing06.30.CallingAnObjectInitializer.cs index 9a2841ae6..43ab5b299 100644 --- a/src/Chapter06/Listing06.30.CallingAnObjectInitializer.cs +++ b/src/Chapter06/Listing06.30.CallingAnObjectInitializer.cs @@ -1,7 +1,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_30; using System.Collections.Generic; -using Listing06_26; +using Listing06_27a; #region INCLUDE public class Program From 351d38f4d46b267f9317e88740366798f1689f47 Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Mon, 11 Sep 2023 09:16:55 +0100 Subject: [PATCH 2/7] Renumber --- .../Listing06.26.DefiningAConstructor.Tests.cs | 2 +- ...sting06.29.DefaultConstructorNoLongerAvailable.Tests.cs} | 6 +++--- ...nObjectInitializerWithExplicitMemberAssignment.Tests.cs} | 2 +- ...sts.cs => Listing06.33.OverloadingAConstructor.Tests.cs} | 2 +- ... Listing06.34.CallingOneConstructorFromAnother.Tests.cs} | 2 +- ...> Listing06.35.ProvidingAnInitializationMethod.Tests.cs} | 2 +- ...6.36.ProvidingValidationOnNon-NullableProperty.Tests.cs} | 2 +- ...fyingRequiredMembersWithinTheObjectInitializer.Tests.cs} | 6 +++--- ....UsingNotNullWhenAndNotNullIfNotNullAttributes.Tests.cs} | 2 +- ...6.42.PotentialNullReturnWithMaybeNullAttribute.Tests.cs} | 2 +- ...> Listing06.43.DefiningAndUsingADeconstructors.Tests.cs} | 2 +- ... Listing06.44.ImplicitlyInvokingDeconstructors.Tests.cs} | 2 +- ...Tests.cs => Listing06.47.AccessingAStaticField.Tests.cs} | 2 +- ...ting06.48.DefiningAStaticMethodOnDirectoryInfo.Tests.cs} | 2 +- ...Tests.cs => Listing06.51.DeclaringAStaticClass.Tests.cs} | 2 +- ...aringAReadOnlyAutomaticallyImplementedProperty.Tests.cs} | 2 +- ....Tests.cs => Listing06.56.DefiningANestedClass.Tests.cs} | 2 +- src/Chapter06/Listing06.27.CallingAConstructor.cs | 2 +- ...AConstructor.cs => Listing06.28.DefiningAConstructor.cs} | 2 +- ... => Listing06.29.DefaultConstructorNoLongerAvailable.cs} | 4 ++-- ...llingAnObjectInitializerWithExplicitMemberAssignment.cs} | 2 +- ...alizer.cs => Listing06.31.CallingAnObjectInitializer.cs} | 4 ++-- ...1.InitOnlySetters.cs => Listing06.32.InitOnlySetters.cs} | 2 +- ...nstructor.cs => Listing06.33.OverloadingAConstructor.cs} | 2 +- ....cs => Listing06.34.CallingOneConstructorFromAnother.cs} | 2 +- ...d.cs => Listing06.35.ProvidingAnInitializationMethod.cs} | 2 +- ...sting06.36.ProvidingValidationOnNon-NullableProperty.cs} | 2 +- ...nNullReferenceTypeAutomaticallyImplementedProperties.cs} | 2 +- ...iredProperties.cs => Listing06.38.RequiredProperties.cs} | 2 +- ....SpecifyingRequiredMembersWithinTheObjectInitializer.cs} | 4 ++-- ...> Listing06.40.DisablingRequiredObjectInitialization.cs} | 2 +- ...g06.41.UsingNotNullWhenAndNotNullIfNotNullAttributes.cs} | 2 +- ...sting06.42.PotentialNullReturnWithMaybeNullAttribute.cs} | 2 +- ...s.cs => Listing06.43.DefiningAndUsingADeconstructors.cs} | 2 +- ....cs => Listing06.44.ImplicitlyInvokingDeconstructors.cs} | 4 ++-- ...StaticField.cs => Listing06.45.DeclaringAStaticField.cs} | 2 +- ...s => Listing06.46.AssigningAStaticFieldAtDeclaration.cs} | 2 +- ...StaticField.cs => Listing06.47.AccessingAStaticField.cs} | 2 +- ...=> Listing06.48.DefiningAStaticMethodOnDirectoryInfo.cs} | 2 +- ...uctor.cs => Listing06.49.DeclaringAStaticConstructor.cs} | 2 +- ...Property.cs => Listing06.50.DeclaringAStaticProperty.cs} | 2 +- ...StaticClass.cs => Listing06.51.DeclaringAStaticClass.cs} | 2 +- ....cs => Listing06.52.StaticCopyMethodForDirectoryInfo.cs} | 2 +- ...tantField.cs => Listing06.53.DeclaringAConstantField.cs} | 2 +- ...eadonly.cs => Listing06.54.DeclaringAFieldAsReadonly.cs} | 2 +- ...5.DeclaringAReadOnlyAutomaticallyImplementedProperty.cs} | 2 +- ...ANestedClass.cs => Listing06.56.DefiningANestedClass.cs} | 2 +- ...artialClass.cs => Listing06.57.DefiningAPartialClass.cs} | 2 +- ...ing06.58.DefiningANestedClassInASeperatePartialClass.cs} | 2 +- ...6.59.DefiningAPartialMethodToAccessItsImplementation.cs} | 2 +- 50 files changed, 58 insertions(+), 58 deletions(-) rename src/Chapter06.Tests/{Listing06.28.Tests.cs => Listing06.29.DefaultConstructorNoLongerAvailable.Tests.cs} (86%) rename src/Chapter06.Tests/{Listing06.29.CallingAnObjectInitializer.Tests.cs => Listing06.30.CallingAnObjectInitializerWithExplicitMemberAssignment.Tests.cs} (96%) rename src/Chapter06.Tests/{Listing06.32.OverloadingAConstructor.Tests.cs => Listing06.33.OverloadingAConstructor.Tests.cs} (96%) rename src/Chapter06.Tests/{Listing06.33.CallingOneConstructorFromAnother.Tests.cs => Listing06.34.CallingOneConstructorFromAnother.Tests.cs} (96%) rename src/Chapter06.Tests/{Listing06.34.ProvidingAnInitializationMethod.Tests.cs => Listing06.35.ProvidingAnInitializationMethod.Tests.cs} (96%) rename src/Chapter06.Tests/{Listing06.35.ProvidingValidationOnNon-NullableProperty.Tests.cs => Listing06.36.ProvidingValidationOnNon-NullableProperty.Tests.cs} (95%) rename src/Chapter06.Tests/{Listing06.38.SpecifyingRequiredMembersWithinTheObjectInitializer.Tests.cs => Listing06.39.SpecifyingRequiredMembersWithinTheObjectInitializer.Tests.cs} (84%) rename src/Chapter06.Tests/{Listing06.40.UsingNotNullWhenAndNotNullIfNotNullAttributes.Tests.cs => Listing06.41.UsingNotNullWhenAndNotNullIfNotNullAttributes.Tests.cs} (98%) rename src/Chapter06.Tests/{Listing06.41.PotentialNullReturnWithMaybeNullAttribute.Tests.cs => Listing06.42.PotentialNullReturnWithMaybeNullAttribute.Tests.cs} (97%) rename src/Chapter06.Tests/{Listing06.42.DefiningAndUsingADeconstructors.Tests.cs => Listing06.43.DefiningAndUsingADeconstructors.Tests.cs} (96%) rename src/Chapter06.Tests/{Listing06.43.ImplicitlyInvokingDeconstructors.Tests.cs => Listing06.44.ImplicitlyInvokingDeconstructors.Tests.cs} (96%) rename src/Chapter06.Tests/{Listing06.46.AccessingAStaticField.Tests.cs => Listing06.47.AccessingAStaticField.Tests.cs} (96%) rename src/Chapter06.Tests/{Listing06.47.DefiningAStaticMethodOnDirectoryInfo.Tests.cs => Listing06.48.DefiningAStaticMethodOnDirectoryInfo.Tests.cs} (98%) rename src/Chapter06.Tests/{Listing06.50.DeclaringAStaticClass.Tests.cs => Listing06.51.DeclaringAStaticClass.Tests.cs} (97%) rename src/Chapter06.Tests/{Listing06.54.DeclaringAReadOnlyAutomaticallyImplementedProperty.Tests.cs => Listing06.55.DeclaringAReadOnlyAutomaticallyImplementedProperty.Tests.cs} (95%) rename src/Chapter06.Tests/{Listing06.55.DefiningANestedClass.Tests.cs => Listing06.56.DefiningANestedClass.Tests.cs} (99%) rename src/Chapter06/{Listing06.27a.DefiningAConstructor.cs => Listing06.28.DefiningAConstructor.cs} (95%) rename src/Chapter06/{Listing06.28.DefaultConstructorNoLongerAvailable.cs => Listing06.29.DefaultConstructorNoLongerAvailable.cs} (94%) rename src/Chapter06/{Listing06.29.CallingAnObjectInitializerWithExplicitMemberAssignment.cs => Listing06.30.CallingAnObjectInitializerWithExplicitMemberAssignment.cs} (95%) rename src/Chapter06/{Listing06.30.CallingAnObjectInitializer.cs => Listing06.31.CallingAnObjectInitializer.cs} (92%) rename src/Chapter06/{Listing06.31.InitOnlySetters.cs => Listing06.32.InitOnlySetters.cs} (99%) rename src/Chapter06/{Listing06.32.OverloadingAConstructor.cs => Listing06.33.OverloadingAConstructor.cs} (99%) rename src/Chapter06/{Listing06.33.CallingOneConstructorFromAnother.cs => Listing06.34.CallingOneConstructorFromAnother.cs} (99%) rename src/Chapter06/{Listing06.34.ProvidingAnInitializationMethod.cs => Listing06.35.ProvidingAnInitializationMethod.cs} (99%) rename src/Chapter06/{Listing06.35.ProvidingValidationOnNon-NullableProperty.cs => Listing06.36.ProvidingValidationOnNon-NullableProperty.cs} (98%) rename src/Chapter06/{Listing06.36.ValidationOfNonNullReferenceTypeAutomaticallyImplementedProperties.cs => Listing06.37.ValidationOfNonNullReferenceTypeAutomaticallyImplementedProperties.cs} (97%) rename src/Chapter06/{Listing06.37.RequiredProperties.cs => Listing06.38.RequiredProperties.cs} (99%) rename src/Chapter06/{Listing06.38.SpecifyingRequiredMembersWithinTheObjectInitializer.cs => Listing06.39.SpecifyingRequiredMembersWithinTheObjectInitializer.cs} (97%) rename src/Chapter06/{Listing06.39.DisablingRequiredObjectInitialization.cs => Listing06.40.DisablingRequiredObjectInitialization.cs} (99%) rename src/Chapter06/{Listing06.40.UsingNotNullWhenAndNotNullIfNotNullAttributes.cs => Listing06.41.UsingNotNullWhenAndNotNullIfNotNullAttributes.cs} (99%) rename src/Chapter06/{Listing06.41.PotentialNullReturnWithMaybeNullAttribute.cs => Listing06.42.PotentialNullReturnWithMaybeNullAttribute.cs} (98%) rename src/Chapter06/{Listing06.42.DefiningAndUsingADeconstructors.cs => Listing06.43.DefiningAndUsingADeconstructors.cs} (99%) rename src/Chapter06/{Listing06.43.ImplicitlyInvokingDeconstructors.cs => Listing06.44.ImplicitlyInvokingDeconstructors.cs} (98%) rename src/Chapter06/{Listing06.44.DeclaringAStaticField.cs => Listing06.45.DeclaringAStaticField.cs} (98%) rename src/Chapter06/{Listing06.45.AssigningAStaticFieldAtDeclaration.cs => Listing06.46.AssigningAStaticFieldAtDeclaration.cs} (95%) rename src/Chapter06/{Listing06.46.AccessingAStaticField.cs => Listing06.47.AccessingAStaticField.cs} (99%) rename src/Chapter06/{Listing06.47.DefiningAStaticMethodOnDirectoryInfo.cs => Listing06.48.DefiningAStaticMethodOnDirectoryInfo.cs} (99%) rename src/Chapter06/{Listing06.48.DeclaringAStaticConstructor.cs => Listing06.49.DeclaringAStaticConstructor.cs} (96%) rename src/Chapter06/{Listing06.49.DeclaringAStaticProperty.cs => Listing06.50.DeclaringAStaticProperty.cs} (97%) rename src/Chapter06/{Listing06.50.DeclaringAStaticClass.cs => Listing06.51.DeclaringAStaticClass.cs} (99%) rename src/Chapter06/{Listing06.51.StaticCopyMethodForDirectoryInfo.cs => Listing06.52.StaticCopyMethodForDirectoryInfo.cs} (99%) rename src/Chapter06/{Listing06.52.DeclaringAConstantField.cs => Listing06.53.DeclaringAConstantField.cs} (95%) rename src/Chapter06/{Listing06.53.DeclaringAFieldAsReadonly.cs => Listing06.54.DeclaringAFieldAsReadonly.cs} (98%) rename src/Chapter06/{Listing06.54.DeclaringAReadOnlyAutomaticallyImplementedProperty.cs => Listing06.55.DeclaringAReadOnlyAutomaticallyImplementedProperty.cs} (99%) rename src/Chapter06/{Listing06.55.DefiningANestedClass.cs => Listing06.56.DefiningANestedClass.cs} (99%) rename src/Chapter06/{Listing06.56.DefiningAPartialClass.cs => Listing06.57.DefiningAPartialClass.cs} (95%) rename src/Chapter06/{Listing06.57.DefiningANestedClassInASeperatePartialClass.cs => Listing06.58.DefiningANestedClassInASeperatePartialClass.cs} (99%) rename src/Chapter06/{Listing06.58.DefiningAPartialMethodToAccessItsImplementation.cs => Listing06.59.DefiningAPartialMethodToAccessItsImplementation.cs} (99%) diff --git a/src/Chapter06.Tests/Listing06.26.DefiningAConstructor.Tests.cs b/src/Chapter06.Tests/Listing06.26.DefiningAConstructor.Tests.cs index dee18be1d..26fe029b2 100644 --- a/src/Chapter06.Tests/Listing06.26.DefiningAConstructor.Tests.cs +++ b/src/Chapter06.Tests/Listing06.26.DefiningAConstructor.Tests.cs @@ -1,6 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_27a.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_28.Tests; [TestClass] public class ProgramTests diff --git a/src/Chapter06.Tests/Listing06.28.Tests.cs b/src/Chapter06.Tests/Listing06.29.DefaultConstructorNoLongerAvailable.Tests.cs similarity index 86% rename from src/Chapter06.Tests/Listing06.28.Tests.cs rename to src/Chapter06.Tests/Listing06.29.DefaultConstructorNoLongerAvailable.Tests.cs index 7ceaae4b7..0a105259a 100644 --- a/src/Chapter06.Tests/Listing06.28.Tests.cs +++ b/src/Chapter06.Tests/Listing06.29.DefaultConstructorNoLongerAvailable.Tests.cs @@ -1,7 +1,7 @@ using AddisonWesley.Michaelis.EssentialCSharp.Shared.Tests; using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_28.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_29.Tests; [TestClass] public class ProgramTests @@ -12,7 +12,7 @@ public async Task UnassignedVariableThrowsError() await CompilerAssert.CompileAsync( new string[] { CompilerAssert.GetTargetFileNameToCompileFromTestFileName(), - "Listing06.26.DefiningAConstructor.cs" }, + "Listing06.28.DefiningAConstructor.cs" }, new string[] { "CS7036" }); } -} \ No newline at end of file +} diff --git a/src/Chapter06.Tests/Listing06.29.CallingAnObjectInitializer.Tests.cs b/src/Chapter06.Tests/Listing06.30.CallingAnObjectInitializerWithExplicitMemberAssignment.Tests.cs similarity index 96% rename from src/Chapter06.Tests/Listing06.29.CallingAnObjectInitializer.Tests.cs rename to src/Chapter06.Tests/Listing06.30.CallingAnObjectInitializerWithExplicitMemberAssignment.Tests.cs index 77f26e4de..292eaee87 100644 --- a/src/Chapter06.Tests/Listing06.29.CallingAnObjectInitializer.Tests.cs +++ b/src/Chapter06.Tests/Listing06.30.CallingAnObjectInitializerWithExplicitMemberAssignment.Tests.cs @@ -1,6 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_29.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_30.Tests; [TestClass] public class ProgramTests diff --git a/src/Chapter06.Tests/Listing06.32.OverloadingAConstructor.Tests.cs b/src/Chapter06.Tests/Listing06.33.OverloadingAConstructor.Tests.cs similarity index 96% rename from src/Chapter06.Tests/Listing06.32.OverloadingAConstructor.Tests.cs rename to src/Chapter06.Tests/Listing06.33.OverloadingAConstructor.Tests.cs index 79fc1bc76..6a997fb31 100644 --- a/src/Chapter06.Tests/Listing06.32.OverloadingAConstructor.Tests.cs +++ b/src/Chapter06.Tests/Listing06.33.OverloadingAConstructor.Tests.cs @@ -1,6 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_32.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_33.Tests; [TestClass] public class EmployeeTests diff --git a/src/Chapter06.Tests/Listing06.33.CallingOneConstructorFromAnother.Tests.cs b/src/Chapter06.Tests/Listing06.34.CallingOneConstructorFromAnother.Tests.cs similarity index 96% rename from src/Chapter06.Tests/Listing06.33.CallingOneConstructorFromAnother.Tests.cs rename to src/Chapter06.Tests/Listing06.34.CallingOneConstructorFromAnother.Tests.cs index 1889b6232..5ab9638c9 100644 --- a/src/Chapter06.Tests/Listing06.33.CallingOneConstructorFromAnother.Tests.cs +++ b/src/Chapter06.Tests/Listing06.34.CallingOneConstructorFromAnother.Tests.cs @@ -1,6 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_33.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_34.Tests; [TestClass] public class EmployeeTests diff --git a/src/Chapter06.Tests/Listing06.34.ProvidingAnInitializationMethod.Tests.cs b/src/Chapter06.Tests/Listing06.35.ProvidingAnInitializationMethod.Tests.cs similarity index 96% rename from src/Chapter06.Tests/Listing06.34.ProvidingAnInitializationMethod.Tests.cs rename to src/Chapter06.Tests/Listing06.35.ProvidingAnInitializationMethod.Tests.cs index 7703520b5..f1a190545 100644 --- a/src/Chapter06.Tests/Listing06.34.ProvidingAnInitializationMethod.Tests.cs +++ b/src/Chapter06.Tests/Listing06.35.ProvidingAnInitializationMethod.Tests.cs @@ -1,6 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_34.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_35.Tests; [TestClass] public class EmployeeTests diff --git a/src/Chapter06.Tests/Listing06.35.ProvidingValidationOnNon-NullableProperty.Tests.cs b/src/Chapter06.Tests/Listing06.36.ProvidingValidationOnNon-NullableProperty.Tests.cs similarity index 95% rename from src/Chapter06.Tests/Listing06.35.ProvidingValidationOnNon-NullableProperty.Tests.cs rename to src/Chapter06.Tests/Listing06.36.ProvidingValidationOnNon-NullableProperty.Tests.cs index 57e9d6155..8d72f2caf 100644 --- a/src/Chapter06.Tests/Listing06.35.ProvidingValidationOnNon-NullableProperty.Tests.cs +++ b/src/Chapter06.Tests/Listing06.36.ProvidingValidationOnNon-NullableProperty.Tests.cs @@ -1,6 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_35.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_36.Tests; [TestClass] public class EmployeeTests diff --git a/src/Chapter06.Tests/Listing06.38.SpecifyingRequiredMembersWithinTheObjectInitializer.Tests.cs b/src/Chapter06.Tests/Listing06.39.SpecifyingRequiredMembersWithinTheObjectInitializer.Tests.cs similarity index 84% rename from src/Chapter06.Tests/Listing06.38.SpecifyingRequiredMembersWithinTheObjectInitializer.Tests.cs rename to src/Chapter06.Tests/Listing06.39.SpecifyingRequiredMembersWithinTheObjectInitializer.Tests.cs index e2e73dfbb..1121c7cd5 100644 --- a/src/Chapter06.Tests/Listing06.38.SpecifyingRequiredMembersWithinTheObjectInitializer.Tests.cs +++ b/src/Chapter06.Tests/Listing06.39.SpecifyingRequiredMembersWithinTheObjectInitializer.Tests.cs @@ -1,7 +1,7 @@ using AddisonWesley.Michaelis.EssentialCSharp.Shared.Tests; using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_38.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_39.Tests; #if NET7_0_OR_GREATER [TestClass] @@ -13,8 +13,8 @@ public async Task NotSpecifyingRequiredMembersWithinTheObjectInitializer() await CompilerAssert.CompileAsync( new string[]{ CompilerAssert.GetTargetFileNameToCompileFromTestFileName(), - "Listing06.37.RequiredProperties.cs"}, + "Listing06.38.RequiredProperties.cs"}, new string[] { "CS9035" }); } } -#endif // NET7_0_OR_GREATER \ No newline at end of file +#endif // NET7_0_OR_GREATER diff --git a/src/Chapter06.Tests/Listing06.40.UsingNotNullWhenAndNotNullIfNotNullAttributes.Tests.cs b/src/Chapter06.Tests/Listing06.41.UsingNotNullWhenAndNotNullIfNotNullAttributes.Tests.cs similarity index 98% rename from src/Chapter06.Tests/Listing06.40.UsingNotNullWhenAndNotNullIfNotNullAttributes.Tests.cs rename to src/Chapter06.Tests/Listing06.41.UsingNotNullWhenAndNotNullIfNotNullAttributes.Tests.cs index a8c56896a..d287036d3 100644 --- a/src/Chapter06.Tests/Listing06.40.UsingNotNullWhenAndNotNullIfNotNullAttributes.Tests.cs +++ b/src/Chapter06.Tests/Listing06.41.UsingNotNullWhenAndNotNullIfNotNullAttributes.Tests.cs @@ -1,6 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_40.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_41.Tests; [TestClass] public class NullabilityAttributesExaminedTests diff --git a/src/Chapter06.Tests/Listing06.41.PotentialNullReturnWithMaybeNullAttribute.Tests.cs b/src/Chapter06.Tests/Listing06.42.PotentialNullReturnWithMaybeNullAttribute.Tests.cs similarity index 97% rename from src/Chapter06.Tests/Listing06.41.PotentialNullReturnWithMaybeNullAttribute.Tests.cs rename to src/Chapter06.Tests/Listing06.42.PotentialNullReturnWithMaybeNullAttribute.Tests.cs index 67b0884a3..171e54103 100644 --- a/src/Chapter06.Tests/Listing06.41.PotentialNullReturnWithMaybeNullAttribute.Tests.cs +++ b/src/Chapter06.Tests/Listing06.42.PotentialNullReturnWithMaybeNullAttribute.Tests.cs @@ -1,6 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_41.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_42.Tests; [TestClass] public class ProgramTests diff --git a/src/Chapter06.Tests/Listing06.42.DefiningAndUsingADeconstructors.Tests.cs b/src/Chapter06.Tests/Listing06.43.DefiningAndUsingADeconstructors.Tests.cs similarity index 96% rename from src/Chapter06.Tests/Listing06.42.DefiningAndUsingADeconstructors.Tests.cs rename to src/Chapter06.Tests/Listing06.43.DefiningAndUsingADeconstructors.Tests.cs index f10973d43..e931fbe5b 100644 --- a/src/Chapter06.Tests/Listing06.42.DefiningAndUsingADeconstructors.Tests.cs +++ b/src/Chapter06.Tests/Listing06.43.DefiningAndUsingADeconstructors.Tests.cs @@ -1,6 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_42.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_43.Tests; [TestClass] public class ProgramTests diff --git a/src/Chapter06.Tests/Listing06.43.ImplicitlyInvokingDeconstructors.Tests.cs b/src/Chapter06.Tests/Listing06.44.ImplicitlyInvokingDeconstructors.Tests.cs similarity index 96% rename from src/Chapter06.Tests/Listing06.43.ImplicitlyInvokingDeconstructors.Tests.cs rename to src/Chapter06.Tests/Listing06.44.ImplicitlyInvokingDeconstructors.Tests.cs index 3ee92c824..c3ea91034 100644 --- a/src/Chapter06.Tests/Listing06.43.ImplicitlyInvokingDeconstructors.Tests.cs +++ b/src/Chapter06.Tests/Listing06.44.ImplicitlyInvokingDeconstructors.Tests.cs @@ -1,6 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_43.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_44.Tests; [TestClass] public class ProgramTests diff --git a/src/Chapter06.Tests/Listing06.46.AccessingAStaticField.Tests.cs b/src/Chapter06.Tests/Listing06.47.AccessingAStaticField.Tests.cs similarity index 96% rename from src/Chapter06.Tests/Listing06.46.AccessingAStaticField.Tests.cs rename to src/Chapter06.Tests/Listing06.47.AccessingAStaticField.Tests.cs index d7401e9a5..c1f3470d7 100644 --- a/src/Chapter06.Tests/Listing06.46.AccessingAStaticField.Tests.cs +++ b/src/Chapter06.Tests/Listing06.47.AccessingAStaticField.Tests.cs @@ -1,6 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_46.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_47.Tests; [TestClass] public class ProgramTests diff --git a/src/Chapter06.Tests/Listing06.47.DefiningAStaticMethodOnDirectoryInfo.Tests.cs b/src/Chapter06.Tests/Listing06.48.DefiningAStaticMethodOnDirectoryInfo.Tests.cs similarity index 98% rename from src/Chapter06.Tests/Listing06.47.DefiningAStaticMethodOnDirectoryInfo.Tests.cs rename to src/Chapter06.Tests/Listing06.48.DefiningAStaticMethodOnDirectoryInfo.Tests.cs index 6ab31d06e..d14b7988d 100644 --- a/src/Chapter06.Tests/Listing06.47.DefiningAStaticMethodOnDirectoryInfo.Tests.cs +++ b/src/Chapter06.Tests/Listing06.48.DefiningAStaticMethodOnDirectoryInfo.Tests.cs @@ -1,6 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_47.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_48.Tests; [TestClass] public class DirectoryTests diff --git a/src/Chapter06.Tests/Listing06.50.DeclaringAStaticClass.Tests.cs b/src/Chapter06.Tests/Listing06.51.DeclaringAStaticClass.Tests.cs similarity index 97% rename from src/Chapter06.Tests/Listing06.50.DeclaringAStaticClass.Tests.cs rename to src/Chapter06.Tests/Listing06.51.DeclaringAStaticClass.Tests.cs index 9d381e45c..c1e09938e 100644 --- a/src/Chapter06.Tests/Listing06.50.DeclaringAStaticClass.Tests.cs +++ b/src/Chapter06.Tests/Listing06.51.DeclaringAStaticClass.Tests.cs @@ -1,6 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_50.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_51.Tests; [TestClass] public class ProgramTests diff --git a/src/Chapter06.Tests/Listing06.54.DeclaringAReadOnlyAutomaticallyImplementedProperty.Tests.cs b/src/Chapter06.Tests/Listing06.55.DeclaringAReadOnlyAutomaticallyImplementedProperty.Tests.cs similarity index 95% rename from src/Chapter06.Tests/Listing06.54.DeclaringAReadOnlyAutomaticallyImplementedProperty.Tests.cs rename to src/Chapter06.Tests/Listing06.55.DeclaringAReadOnlyAutomaticallyImplementedProperty.Tests.cs index fa570c98a..037baa2cd 100644 --- a/src/Chapter06.Tests/Listing06.54.DeclaringAReadOnlyAutomaticallyImplementedProperty.Tests.cs +++ b/src/Chapter06.Tests/Listing06.55.DeclaringAReadOnlyAutomaticallyImplementedProperty.Tests.cs @@ -1,6 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_54.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_55.Tests; [TestClass] public class DirectoryTests diff --git a/src/Chapter06.Tests/Listing06.55.DefiningANestedClass.Tests.cs b/src/Chapter06.Tests/Listing06.56.DefiningANestedClass.Tests.cs similarity index 99% rename from src/Chapter06.Tests/Listing06.55.DefiningANestedClass.Tests.cs rename to src/Chapter06.Tests/Listing06.56.DefiningANestedClass.Tests.cs index f76612e62..d764001b4 100644 --- a/src/Chapter06.Tests/Listing06.55.DefiningANestedClass.Tests.cs +++ b/src/Chapter06.Tests/Listing06.56.DefiningANestedClass.Tests.cs @@ -1,6 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_55.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_56.Tests; [TestClass] public class ProgramTests diff --git a/src/Chapter06/Listing06.27.CallingAConstructor.cs b/src/Chapter06/Listing06.27.CallingAConstructor.cs index b990f570b..6608fa1ec 100644 --- a/src/Chapter06/Listing06.27.CallingAConstructor.cs +++ b/src/Chapter06/Listing06.27.CallingAConstructor.cs @@ -1,6 +1,6 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_27; -using Listing06_27a; +using Listing06_28; #region INCLUDE public class Program diff --git a/src/Chapter06/Listing06.27a.DefiningAConstructor.cs b/src/Chapter06/Listing06.28.DefiningAConstructor.cs similarity index 95% rename from src/Chapter06/Listing06.27a.DefiningAConstructor.cs rename to src/Chapter06/Listing06.28.DefiningAConstructor.cs index 48939b9e8..15eaa4b86 100644 --- a/src/Chapter06/Listing06.27a.DefiningAConstructor.cs +++ b/src/Chapter06/Listing06.28.DefiningAConstructor.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_27a; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_28; public class Program { diff --git a/src/Chapter06/Listing06.28.DefaultConstructorNoLongerAvailable.cs b/src/Chapter06/Listing06.29.DefaultConstructorNoLongerAvailable.cs similarity index 94% rename from src/Chapter06/Listing06.28.DefaultConstructorNoLongerAvailable.cs rename to src/Chapter06/Listing06.29.DefaultConstructorNoLongerAvailable.cs index fccb0eec1..8919cf678 100644 --- a/src/Chapter06/Listing06.28.DefaultConstructorNoLongerAvailable.cs +++ b/src/Chapter06/Listing06.29.DefaultConstructorNoLongerAvailable.cs @@ -1,9 +1,9 @@ // Variable is declared but never used #pragma warning disable CS0168 -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_28; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_29; -using Listing06_27a; +using Listing06_28; #region INCLUDE public class Program diff --git a/src/Chapter06/Listing06.29.CallingAnObjectInitializerWithExplicitMemberAssignment.cs b/src/Chapter06/Listing06.30.CallingAnObjectInitializerWithExplicitMemberAssignment.cs similarity index 95% rename from src/Chapter06/Listing06.29.CallingAnObjectInitializerWithExplicitMemberAssignment.cs rename to src/Chapter06/Listing06.30.CallingAnObjectInitializerWithExplicitMemberAssignment.cs index 58d93de48..467be988e 100644 --- a/src/Chapter06/Listing06.29.CallingAnObjectInitializerWithExplicitMemberAssignment.cs +++ b/src/Chapter06/Listing06.30.CallingAnObjectInitializerWithExplicitMemberAssignment.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_29; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_30; #region INCLUDE public class Program diff --git a/src/Chapter06/Listing06.30.CallingAnObjectInitializer.cs b/src/Chapter06/Listing06.31.CallingAnObjectInitializer.cs similarity index 92% rename from src/Chapter06/Listing06.30.CallingAnObjectInitializer.cs rename to src/Chapter06/Listing06.31.CallingAnObjectInitializer.cs index 43ab5b299..8293396b9 100644 --- a/src/Chapter06/Listing06.30.CallingAnObjectInitializer.cs +++ b/src/Chapter06/Listing06.31.CallingAnObjectInitializer.cs @@ -1,7 +1,7 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_30; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_31; using System.Collections.Generic; -using Listing06_27a; +using Listing06_28; #region INCLUDE public class Program diff --git a/src/Chapter06/Listing06.31.InitOnlySetters.cs b/src/Chapter06/Listing06.32.InitOnlySetters.cs similarity index 99% rename from src/Chapter06/Listing06.31.InitOnlySetters.cs rename to src/Chapter06/Listing06.32.InitOnlySetters.cs index f232e69a0..c60ff9291 100644 --- a/src/Chapter06/Listing06.31.InitOnlySetters.cs +++ b/src/Chapter06/Listing06.32.InitOnlySetters.cs @@ -1,7 +1,7 @@ // Non-nullable field is uninitialized. Consider declaring as nullable. #pragma warning disable CS8618 // Pending a constructors -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_31; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_32; #region INCLUDE public class Employee diff --git a/src/Chapter06/Listing06.32.OverloadingAConstructor.cs b/src/Chapter06/Listing06.33.OverloadingAConstructor.cs similarity index 99% rename from src/Chapter06/Listing06.32.OverloadingAConstructor.cs rename to src/Chapter06/Listing06.33.OverloadingAConstructor.cs index 1546ae7ea..8fd2a432b 100644 --- a/src/Chapter06/Listing06.32.OverloadingAConstructor.cs +++ b/src/Chapter06/Listing06.33.OverloadingAConstructor.cs @@ -2,7 +2,7 @@ #pragma warning disable IDE0044 #pragma warning disable 649 // _Id is never assigned -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_32; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_33; #region INCLUDE public class Employee diff --git a/src/Chapter06/Listing06.33.CallingOneConstructorFromAnother.cs b/src/Chapter06/Listing06.34.CallingOneConstructorFromAnother.cs similarity index 99% rename from src/Chapter06/Listing06.33.CallingOneConstructorFromAnother.cs rename to src/Chapter06/Listing06.34.CallingOneConstructorFromAnother.cs index 5bd312e45..2d3429a91 100644 --- a/src/Chapter06/Listing06.33.CallingOneConstructorFromAnother.cs +++ b/src/Chapter06/Listing06.34.CallingOneConstructorFromAnother.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_33; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_34; #region INCLUDE public class Employee diff --git a/src/Chapter06/Listing06.34.ProvidingAnInitializationMethod.cs b/src/Chapter06/Listing06.35.ProvidingAnInitializationMethod.cs similarity index 99% rename from src/Chapter06/Listing06.34.ProvidingAnInitializationMethod.cs rename to src/Chapter06/Listing06.35.ProvidingAnInitializationMethod.cs index 475bbeca8..c0eb3d5c9 100644 --- a/src/Chapter06/Listing06.34.ProvidingAnInitializationMethod.cs +++ b/src/Chapter06/Listing06.35.ProvidingAnInitializationMethod.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_34; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_35; public class Program { diff --git a/src/Chapter06/Listing06.35.ProvidingValidationOnNon-NullableProperty.cs b/src/Chapter06/Listing06.36.ProvidingValidationOnNon-NullableProperty.cs similarity index 98% rename from src/Chapter06/Listing06.35.ProvidingValidationOnNon-NullableProperty.cs rename to src/Chapter06/Listing06.36.ProvidingValidationOnNon-NullableProperty.cs index fbaea9ba8..02b6bef67 100644 --- a/src/Chapter06/Listing06.35.ProvidingValidationOnNon-NullableProperty.cs +++ b/src/Chapter06/Listing06.36.ProvidingValidationOnNon-NullableProperty.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_35; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_36; using System; diff --git a/src/Chapter06/Listing06.36.ValidationOfNonNullReferenceTypeAutomaticallyImplementedProperties.cs b/src/Chapter06/Listing06.37.ValidationOfNonNullReferenceTypeAutomaticallyImplementedProperties.cs similarity index 97% rename from src/Chapter06/Listing06.36.ValidationOfNonNullReferenceTypeAutomaticallyImplementedProperties.cs rename to src/Chapter06/Listing06.37.ValidationOfNonNullReferenceTypeAutomaticallyImplementedProperties.cs index 96c38a6d0..bd115a6c3 100644 --- a/src/Chapter06/Listing06.36.ValidationOfNonNullReferenceTypeAutomaticallyImplementedProperties.cs +++ b/src/Chapter06/Listing06.37.ValidationOfNonNullReferenceTypeAutomaticallyImplementedProperties.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_36; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_37; using System; diff --git a/src/Chapter06/Listing06.37.RequiredProperties.cs b/src/Chapter06/Listing06.38.RequiredProperties.cs similarity index 99% rename from src/Chapter06/Listing06.37.RequiredProperties.cs rename to src/Chapter06/Listing06.38.RequiredProperties.cs index e09e7e336..505c87d51 100644 --- a/src/Chapter06/Listing06.37.RequiredProperties.cs +++ b/src/Chapter06/Listing06.38.RequiredProperties.cs @@ -1,6 +1,6 @@ #if NET7_0_OR_GREATER -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_37; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_38; #region INCLUDE public class Book diff --git a/src/Chapter06/Listing06.38.SpecifyingRequiredMembersWithinTheObjectInitializer.cs b/src/Chapter06/Listing06.39.SpecifyingRequiredMembersWithinTheObjectInitializer.cs similarity index 97% rename from src/Chapter06/Listing06.38.SpecifyingRequiredMembersWithinTheObjectInitializer.cs rename to src/Chapter06/Listing06.39.SpecifyingRequiredMembersWithinTheObjectInitializer.cs index 4e40eca6c..f3004b9a3 100644 --- a/src/Chapter06/Listing06.38.SpecifyingRequiredMembersWithinTheObjectInitializer.cs +++ b/src/Chapter06/Listing06.39.SpecifyingRequiredMembersWithinTheObjectInitializer.cs @@ -1,12 +1,12 @@ #if NET7_0_OR_GREATER #if COMPILEERROR // EXCLUDE -using AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_37; +using AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_38; #endif // COMPILEERROR // EXCLUDE using System.Runtime.CompilerServices; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_38; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_39; public class Program { diff --git a/src/Chapter06/Listing06.39.DisablingRequiredObjectInitialization.cs b/src/Chapter06/Listing06.40.DisablingRequiredObjectInitialization.cs similarity index 99% rename from src/Chapter06/Listing06.39.DisablingRequiredObjectInitialization.cs rename to src/Chapter06/Listing06.40.DisablingRequiredObjectInitialization.cs index 6dd35fca7..e11399fb8 100644 --- a/src/Chapter06/Listing06.39.DisablingRequiredObjectInitialization.cs +++ b/src/Chapter06/Listing06.40.DisablingRequiredObjectInitialization.cs @@ -1,7 +1,7 @@ #if NET7_0_OR_GREATER using System.Diagnostics.CodeAnalysis; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_39; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_40; public class Program { diff --git a/src/Chapter06/Listing06.40.UsingNotNullWhenAndNotNullIfNotNullAttributes.cs b/src/Chapter06/Listing06.41.UsingNotNullWhenAndNotNullIfNotNullAttributes.cs similarity index 99% rename from src/Chapter06/Listing06.40.UsingNotNullWhenAndNotNullIfNotNullAttributes.cs rename to src/Chapter06/Listing06.41.UsingNotNullWhenAndNotNullIfNotNullAttributes.cs index 344e0bcb8..74921691a 100644 --- a/src/Chapter06/Listing06.40.UsingNotNullWhenAndNotNullIfNotNullAttributes.cs +++ b/src/Chapter06/Listing06.41.UsingNotNullWhenAndNotNullIfNotNullAttributes.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_40; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_41; #region INCLUDE using System.Diagnostics.CodeAnalysis; diff --git a/src/Chapter06/Listing06.41.PotentialNullReturnWithMaybeNullAttribute.cs b/src/Chapter06/Listing06.42.PotentialNullReturnWithMaybeNullAttribute.cs similarity index 98% rename from src/Chapter06/Listing06.41.PotentialNullReturnWithMaybeNullAttribute.cs rename to src/Chapter06/Listing06.42.PotentialNullReturnWithMaybeNullAttribute.cs index e9d4d3899..c3b118105 100644 --- a/src/Chapter06/Listing06.41.PotentialNullReturnWithMaybeNullAttribute.cs +++ b/src/Chapter06/Listing06.42.PotentialNullReturnWithMaybeNullAttribute.cs @@ -1,5 +1,5 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_41; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_42; using System; using System.Diagnostics.CodeAnalysis; diff --git a/src/Chapter06/Listing06.42.DefiningAndUsingADeconstructors.cs b/src/Chapter06/Listing06.43.DefiningAndUsingADeconstructors.cs similarity index 99% rename from src/Chapter06/Listing06.42.DefiningAndUsingADeconstructors.cs rename to src/Chapter06/Listing06.43.DefiningAndUsingADeconstructors.cs index 41f7efcdb..679f4e70a 100644 --- a/src/Chapter06/Listing06.42.DefiningAndUsingADeconstructors.cs +++ b/src/Chapter06/Listing06.43.DefiningAndUsingADeconstructors.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_42; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_43; #region INCLUDE public class Employee diff --git a/src/Chapter06/Listing06.43.ImplicitlyInvokingDeconstructors.cs b/src/Chapter06/Listing06.44.ImplicitlyInvokingDeconstructors.cs similarity index 98% rename from src/Chapter06/Listing06.43.ImplicitlyInvokingDeconstructors.cs rename to src/Chapter06/Listing06.44.ImplicitlyInvokingDeconstructors.cs index d6b6f5470..e8c773224 100644 --- a/src/Chapter06/Listing06.43.ImplicitlyInvokingDeconstructors.cs +++ b/src/Chapter06/Listing06.44.ImplicitlyInvokingDeconstructors.cs @@ -1,6 +1,6 @@ -using AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_42; +using AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_43; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_43; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_44; #region INCLUDE public class Program diff --git a/src/Chapter06/Listing06.44.DeclaringAStaticField.cs b/src/Chapter06/Listing06.45.DeclaringAStaticField.cs similarity index 98% rename from src/Chapter06/Listing06.44.DeclaringAStaticField.cs rename to src/Chapter06/Listing06.45.DeclaringAStaticField.cs index b42cb7a16..d6848ede6 100644 --- a/src/Chapter06/Listing06.44.DeclaringAStaticField.cs +++ b/src/Chapter06/Listing06.45.DeclaringAStaticField.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_44; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_45; #region INCLUDE public class Employee diff --git a/src/Chapter06/Listing06.45.AssigningAStaticFieldAtDeclaration.cs b/src/Chapter06/Listing06.46.AssigningAStaticFieldAtDeclaration.cs similarity index 95% rename from src/Chapter06/Listing06.45.AssigningAStaticFieldAtDeclaration.cs rename to src/Chapter06/Listing06.46.AssigningAStaticFieldAtDeclaration.cs index c1d2a9fec..3e5fbadfe 100644 --- a/src/Chapter06/Listing06.45.AssigningAStaticFieldAtDeclaration.cs +++ b/src/Chapter06/Listing06.46.AssigningAStaticFieldAtDeclaration.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_45; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_46; #region INCLUDE public class Employee diff --git a/src/Chapter06/Listing06.46.AccessingAStaticField.cs b/src/Chapter06/Listing06.47.AccessingAStaticField.cs similarity index 99% rename from src/Chapter06/Listing06.46.AccessingAStaticField.cs rename to src/Chapter06/Listing06.47.AccessingAStaticField.cs index 77cf1380a..c4c8e7122 100644 --- a/src/Chapter06/Listing06.46.AccessingAStaticField.cs +++ b/src/Chapter06/Listing06.47.AccessingAStaticField.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_46; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_47; #region INCLUDE using System; diff --git a/src/Chapter06/Listing06.47.DefiningAStaticMethodOnDirectoryInfo.cs b/src/Chapter06/Listing06.48.DefiningAStaticMethodOnDirectoryInfo.cs similarity index 99% rename from src/Chapter06/Listing06.47.DefiningAStaticMethodOnDirectoryInfo.cs rename to src/Chapter06/Listing06.48.DefiningAStaticMethodOnDirectoryInfo.cs index 51240ce91..e3d4ec0f7 100644 --- a/src/Chapter06/Listing06.47.DefiningAStaticMethodOnDirectoryInfo.cs +++ b/src/Chapter06/Listing06.48.DefiningAStaticMethodOnDirectoryInfo.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_47; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_48; using System; using System.IO; diff --git a/src/Chapter06/Listing06.48.DeclaringAStaticConstructor.cs b/src/Chapter06/Listing06.49.DeclaringAStaticConstructor.cs similarity index 96% rename from src/Chapter06/Listing06.48.DeclaringAStaticConstructor.cs rename to src/Chapter06/Listing06.49.DeclaringAStaticConstructor.cs index 53b6ed29c..3079b66f0 100644 --- a/src/Chapter06/Listing06.48.DeclaringAStaticConstructor.cs +++ b/src/Chapter06/Listing06.49.DeclaringAStaticConstructor.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_48; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_49; using System; diff --git a/src/Chapter06/Listing06.49.DeclaringAStaticProperty.cs b/src/Chapter06/Listing06.50.DeclaringAStaticProperty.cs similarity index 97% rename from src/Chapter06/Listing06.49.DeclaringAStaticProperty.cs rename to src/Chapter06/Listing06.50.DeclaringAStaticProperty.cs index f88178c7d..d79759aa9 100644 --- a/src/Chapter06/Listing06.49.DeclaringAStaticProperty.cs +++ b/src/Chapter06/Listing06.50.DeclaringAStaticProperty.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_49; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_50; #region INCLUDE public class Employee diff --git a/src/Chapter06/Listing06.50.DeclaringAStaticClass.cs b/src/Chapter06/Listing06.51.DeclaringAStaticClass.cs similarity index 99% rename from src/Chapter06/Listing06.50.DeclaringAStaticClass.cs rename to src/Chapter06/Listing06.51.DeclaringAStaticClass.cs index 367ed215c..43b35c477 100644 --- a/src/Chapter06/Listing06.50.DeclaringAStaticClass.cs +++ b/src/Chapter06/Listing06.51.DeclaringAStaticClass.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_50; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_51; using System; using static SimpleMath; diff --git a/src/Chapter06/Listing06.51.StaticCopyMethodForDirectoryInfo.cs b/src/Chapter06/Listing06.52.StaticCopyMethodForDirectoryInfo.cs similarity index 99% rename from src/Chapter06/Listing06.51.StaticCopyMethodForDirectoryInfo.cs rename to src/Chapter06/Listing06.52.StaticCopyMethodForDirectoryInfo.cs index c7f996a3f..053f5376b 100644 --- a/src/Chapter06/Listing06.51.StaticCopyMethodForDirectoryInfo.cs +++ b/src/Chapter06/Listing06.52.StaticCopyMethodForDirectoryInfo.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_51; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_52; using System; using System.IO; diff --git a/src/Chapter06/Listing06.52.DeclaringAConstantField.cs b/src/Chapter06/Listing06.53.DeclaringAConstantField.cs similarity index 95% rename from src/Chapter06/Listing06.52.DeclaringAConstantField.cs rename to src/Chapter06/Listing06.53.DeclaringAConstantField.cs index 9049f86a5..314b8991c 100644 --- a/src/Chapter06/Listing06.52.DeclaringAConstantField.cs +++ b/src/Chapter06/Listing06.53.DeclaringAConstantField.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_52; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_53; #region INCLUDE public class ConvertUnits diff --git a/src/Chapter06/Listing06.53.DeclaringAFieldAsReadonly.cs b/src/Chapter06/Listing06.54.DeclaringAFieldAsReadonly.cs similarity index 98% rename from src/Chapter06/Listing06.53.DeclaringAFieldAsReadonly.cs rename to src/Chapter06/Listing06.54.DeclaringAFieldAsReadonly.cs index 19ca85741..64f7c0656 100644 --- a/src/Chapter06/Listing06.53.DeclaringAFieldAsReadonly.cs +++ b/src/Chapter06/Listing06.54.DeclaringAFieldAsReadonly.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_53; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_54; #region INCLUDE public class Employee diff --git a/src/Chapter06/Listing06.54.DeclaringAReadOnlyAutomaticallyImplementedProperty.cs b/src/Chapter06/Listing06.55.DeclaringAReadOnlyAutomaticallyImplementedProperty.cs similarity index 99% rename from src/Chapter06/Listing06.54.DeclaringAReadOnlyAutomaticallyImplementedProperty.cs rename to src/Chapter06/Listing06.55.DeclaringAReadOnlyAutomaticallyImplementedProperty.cs index 32a157117..45d006f99 100644 --- a/src/Chapter06/Listing06.54.DeclaringAReadOnlyAutomaticallyImplementedProperty.cs +++ b/src/Chapter06/Listing06.55.DeclaringAReadOnlyAutomaticallyImplementedProperty.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_54; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_55; using System; diff --git a/src/Chapter06/Listing06.55.DefiningANestedClass.cs b/src/Chapter06/Listing06.56.DefiningANestedClass.cs similarity index 99% rename from src/Chapter06/Listing06.55.DefiningANestedClass.cs rename to src/Chapter06/Listing06.56.DefiningANestedClass.cs index f4f77425d..7a1c8133f 100644 --- a/src/Chapter06/Listing06.55.DefiningANestedClass.cs +++ b/src/Chapter06/Listing06.56.DefiningANestedClass.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_55; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_56; using System; diff --git a/src/Chapter06/Listing06.56.DefiningAPartialClass.cs b/src/Chapter06/Listing06.57.DefiningAPartialClass.cs similarity index 95% rename from src/Chapter06/Listing06.56.DefiningAPartialClass.cs rename to src/Chapter06/Listing06.57.DefiningAPartialClass.cs index 0a051f81c..073de36fd 100644 --- a/src/Chapter06/Listing06.56.DefiningAPartialClass.cs +++ b/src/Chapter06/Listing06.57.DefiningAPartialClass.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_56; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_57; #region INCLUDE // File: Program1.cs diff --git a/src/Chapter06/Listing06.57.DefiningANestedClassInASeperatePartialClass.cs b/src/Chapter06/Listing06.58.DefiningANestedClassInASeperatePartialClass.cs similarity index 99% rename from src/Chapter06/Listing06.57.DefiningANestedClassInASeperatePartialClass.cs rename to src/Chapter06/Listing06.58.DefiningANestedClassInASeperatePartialClass.cs index ad8c80c16..aada32911 100644 --- a/src/Chapter06/Listing06.57.DefiningANestedClassInASeperatePartialClass.cs +++ b/src/Chapter06/Listing06.58.DefiningANestedClassInASeperatePartialClass.cs @@ -1,7 +1,7 @@ // Ignored as implementation was removed for elucidation #pragma warning disable IDE0060 //Remove unused parameter -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_57; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_58; using System; diff --git a/src/Chapter06/Listing06.58.DefiningAPartialMethodToAccessItsImplementation.cs b/src/Chapter06/Listing06.59.DefiningAPartialMethodToAccessItsImplementation.cs similarity index 99% rename from src/Chapter06/Listing06.58.DefiningAPartialMethodToAccessItsImplementation.cs rename to src/Chapter06/Listing06.59.DefiningAPartialMethodToAccessItsImplementation.cs index c26e553eb..e71e95aa7 100644 --- a/src/Chapter06/Listing06.58.DefiningAPartialMethodToAccessItsImplementation.cs +++ b/src/Chapter06/Listing06.59.DefiningAPartialMethodToAccessItsImplementation.cs @@ -1,7 +1,7 @@ // Non-nullable field is uninitialized. Consider declaring as nullable. #pragma warning disable CS8618 // Pending a constructors -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_58; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_59; using System; From c5da2cc08fee44d3abbf2130d214b5c71fca3b01 Mon Sep 17 00:00:00 2001 From: Benjamin Michaelis Date: Fri, 15 Sep 2023 06:39:02 +0100 Subject: [PATCH 3/7] Update Listing06.26.DefiningAPrimaryConstructor.cs Co-authored-by: Kevin B --- src/Chapter06/Listing06.26.DefiningAPrimaryConstructor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Chapter06/Listing06.26.DefiningAPrimaryConstructor.cs b/src/Chapter06/Listing06.26.DefiningAPrimaryConstructor.cs index 767dc1f8c..0412255f2 100644 --- a/src/Chapter06/Listing06.26.DefiningAPrimaryConstructor.cs +++ b/src/Chapter06/Listing06.26.DefiningAPrimaryConstructor.cs @@ -32,7 +32,7 @@ public class Employee(string firstName, string lastName) public Employee? Manager { get; set; } // Name property - public string Name + public string FullName { get { From b9e7590282d27e7a3ae46419474ebc3346b72a50 Mon Sep 17 00:00:00 2001 From: Benjamin Michaelis Date: Fri, 15 Sep 2023 06:39:41 +0100 Subject: [PATCH 4/7] Update Listing06.26.DefiningAPrimaryConstructor.cs Co-authored-by: Kevin B --- src/Chapter06/Listing06.26.DefiningAPrimaryConstructor.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Chapter06/Listing06.26.DefiningAPrimaryConstructor.cs b/src/Chapter06/Listing06.26.DefiningAPrimaryConstructor.cs index 0412255f2..d9fb101be 100644 --- a/src/Chapter06/Listing06.26.DefiningAPrimaryConstructor.cs +++ b/src/Chapter06/Listing06.26.DefiningAPrimaryConstructor.cs @@ -42,8 +42,7 @@ public string FullName { // Split the assigned value into // first and last names - string[] names; - names = value.Split(new char[] { ' ' }); + string[] names = value.Split(' '); if(names.Length == 2) { FirstName = names[0]; From 409aabce5872f75c72e5b4bd8f8a19ae6e319c7a Mon Sep 17 00:00:00 2001 From: Benjamin Michaelis Date: Fri, 15 Sep 2023 06:40:04 +0100 Subject: [PATCH 5/7] Update Listing06.26.DefiningAPrimaryConstructor.cs Co-authored-by: Kevin B --- src/Chapter06/Listing06.26.DefiningAPrimaryConstructor.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Chapter06/Listing06.26.DefiningAPrimaryConstructor.cs b/src/Chapter06/Listing06.26.DefiningAPrimaryConstructor.cs index d9fb101be..b226c8dba 100644 --- a/src/Chapter06/Listing06.26.DefiningAPrimaryConstructor.cs +++ b/src/Chapter06/Listing06.26.DefiningAPrimaryConstructor.cs @@ -53,9 +53,8 @@ public string FullName // Throw an exception if the full // name was not assigned throw new System.ArgumentException( - string.Format( - $"Assigned value '{ value }' is invalid", - nameof(value))); + $"Assigned value '{ value }' is invalid", + nameof(value)); } } } From 0115e9a6f2530c9bef8d3b650d3ae361d84fbbf8 Mon Sep 17 00:00:00 2001 From: Benjamin Michaelis Date: Fri, 15 Sep 2023 06:41:20 +0100 Subject: [PATCH 6/7] Update Listing06.26.DefiningAPrimaryConstructor.cs Co-authored-by: Kevin B --- src/Chapter06/Listing06.26.DefiningAPrimaryConstructor.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Chapter06/Listing06.26.DefiningAPrimaryConstructor.cs b/src/Chapter06/Listing06.26.DefiningAPrimaryConstructor.cs index b226c8dba..06f1d4dfc 100644 --- a/src/Chapter06/Listing06.26.DefiningAPrimaryConstructor.cs +++ b/src/Chapter06/Listing06.26.DefiningAPrimaryConstructor.cs @@ -10,10 +10,7 @@ public static void Main() employee.Salary = "Too Little"; System.Console.WriteLine( - "{0} {1}: {2}", - employee.FirstName, - employee.LastName, - employee.Salary); + $"{employee.FirstName} {employee.LastName}: {employee.Salary}"); } } From 7e82091178ecf5d878073cb97257bacba9f2adac Mon Sep 17 00:00:00 2001 From: Benjamin Michaelis Date: Fri, 15 Sep 2023 06:46:04 +0100 Subject: [PATCH 7/7] Update Listing06.26.DefiningAPrimaryConstructor.cs Co-authored-by: Kevin B --- src/Chapter06/Listing06.26.DefiningAPrimaryConstructor.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Chapter06/Listing06.26.DefiningAPrimaryConstructor.cs b/src/Chapter06/Listing06.26.DefiningAPrimaryConstructor.cs index 06f1d4dfc..8f4d82d8f 100644 --- a/src/Chapter06/Listing06.26.DefiningAPrimaryConstructor.cs +++ b/src/Chapter06/Listing06.26.DefiningAPrimaryConstructor.cs @@ -5,8 +5,7 @@ public class Program { public static void Main() { - Employee employee; - employee = new("Inigo", "Montoya"); + Employee employee = new("Inigo", "Montoya"); employee.Salary = "Too Little"; System.Console.WriteLine(