From 606913e541dfa29e5695c94807f59dd204fd68b2 Mon Sep 17 00:00:00 2001 From: Kevin Bost Date: Tue, 5 Jul 2022 13:23:46 -0700 Subject: [PATCH 01/13] Changes from pdf review Minor changes from pdf review Chapter 13 first changes Chapter 12 Regions through 12.6 Reviewed through 12.4 Changes from pdf review Changes from pdf review Minor changes from pdf review Chapter 14 initial changes chapter 14 code changes Changes from pdf review Minor changes from pdf review Chapter 15 initial changes chapter 13 review changes adding ... to beginning and end minor ch. 15 changes preventing line rollovers ch. 14 final (hopefully) ch. 14 changes Final ch. 15 changes chapter 15 formatting changes chapter 15 removing redundancies Revert "Changes from pdf review" This reverts commit e114c2cd40f0c3743dac45ed2264805f31b4a953. Revert "Minor changes from pdf review" This reverts commit 47d535e78b386baf3c5ec878a929ada981362996. Revert "Chapter 13 first changes" This reverts commit b211cf35264d0591d1f836a506f36598cecb3857. --- pp_region.snippet | 28 ++++++++++++++++ ...AndCoolerEventSubscriberImplementations.cs | 12 ++++--- ...4.02.DefiningTheEventPublsherThermostat.cs | 16 ++------- ...03.ConnectingThePublisherAndSubscribers.cs | 12 ++++--- ...InvokingADelegateWithoutCheckingForNull.cs | 18 +++++++--- .../Listing14.05.InvokingADelegate.cs | 5 ++- .../Listing14.06.InvokingADelegatePre6.cs | 9 ++++- ...usEqualsAndMinusEqualsDelegateOperators.cs | 12 +++++-- ...8.UsingThePlusAndMinusDelegateOperators.cs | 11 ++++++- ...OnTemperatureChangedThrowingAnException.cs | 14 ++++---- ...14.10.HandlingExceptionsFromSubscribers.cs | 12 ++++--- ...AssignmentOperationRatherThanPlusEquals.cs | 13 ++++---- ...ingTheEventFromOutsideTheEventContainer.cs | 7 ++-- ...heEventKeywordWithTheEventCodingPattern.cs | 7 +++- ...ting14.14.DeclaringAGenericDelegateType.cs | 5 ++- ...Listing14.15.FiringTheEventNotification.cs | 7 +++- .../Listing14.16.UsingCustomDelegateType.cs | 13 ++++---- ...17.DeclaringTheOnTemperatureChangeEvent.cs | 8 +++-- ...SharpConceptualEquivalentOfEventCILCode.cs | 33 +++++++++++-------- ...Listing14.19.CustomAddAndRemoveHandlers.cs | 24 ++++++++++---- .../Listing15.01.CollectionInitialization.cs | 2 ++ .../Listing15.02.DictionaryInitializers.cs | 5 ++- .../Listing15.03.ForeachWithArrays.cs | 2 ++ ...mpiledImplementationOfForeachWithArrays.cs | 2 ++ ...5.05.IteratingOverACollectionUsingWhile.cs | 12 +++++++ ...eratorMaintainingStateDuringAnIteration.cs | 2 ++ ...07.CompiledResultOfForeachOnCollections.cs | 2 ++ ...rrorHandlingAndResourceCleanupWithUsing.cs | 8 +++-- ...lteringWithSystem.Linq.Enumerable.Where.cs | 6 ++++ ...ectionWithSystem.Linq.Enumerable.Select.cs | 6 ++++ ...ectionWithSystem.Linq.Enumerable.Select.cs | 6 ++-- .../Listing15.13.ProjectionToATuple.cs | 12 +++---- ...ing15.14.ExecutingLinqQueriesInParallel.cs | 10 ++++-- .../Listing15.15.CountingItemsWithCount.cs | 9 +++-- ...lteringWithSystem.Linq.Enumerable.Where.cs | 6 ++++ ...System.Linq.Enumerable.OrderByAndThenBy.cs | 7 +++- ...nerJoinUsingSystem.Linq.Enumerable.Join.cs | 14 +++++--- ...nnerJoinWithSystem.Linq.Enumerable.Join.cs | 9 +++-- ...therUsingSystem.Linq.Enumerable.GroupBy.cs | 7 ++-- ...ionWithSystem.Linq.Enumerable.GroupJoin.cs | 13 ++++++-- ...AnOuterJoinUsingGroupJoinWithSelectMany.cs | 5 +++ .../Listing15.24.CallingSelectMany.cs | 10 ++++-- ...5.MoreSystem.Linq.EnumerableMethodCalls.cs | 22 ++++++++++--- ...mplicitLocalVariablesWithAnonymousTypes.cs | 4 +++ ...isting15.27.ProjectionToAnAnonymousType.cs | 10 ++++-- ...peSafetyAndImmutabilityOfAnonymousTypes.cs | 9 +++-- ...ng15.29.InitializingAnonymousTypeArrays.cs | 2 ++ 47 files changed, 344 insertions(+), 124 deletions(-) create mode 100644 pp_region.snippet diff --git a/pp_region.snippet b/pp_region.snippet new file mode 100644 index 000000000..44b8f27bc --- /dev/null +++ b/pp_region.snippet @@ -0,0 +1,28 @@ + + + +
+ #region + #region + Essential C# Region + Microsoft Corporation + + Expansion + SurroundsWith + +
+ + + + name + Region name + MyRegion + + + + + +
+
\ No newline at end of file diff --git a/src/Chapter14/Listing14.01.HeaterAndCoolerEventSubscriberImplementations.cs b/src/Chapter14/Listing14.01.HeaterAndCoolerEventSubscriberImplementations.cs index 31cdf4761..2bf66aa44 100644 --- a/src/Chapter14/Listing14.01.HeaterAndCoolerEventSubscriberImplementations.cs +++ b/src/Chapter14/Listing14.01.HeaterAndCoolerEventSubscriberImplementations.cs @@ -1,13 +1,15 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_01 { - class Cooler + #region INCLUDE + public class Cooler { public Cooler(float temperature) { Temperature = temperature; } - // Cooler is activated when ambient temperature is higher than this + // Cooler is activated when ambient temperature + // is higher than this public float Temperature { get; set; } // Notifies that the temperature changed on this instance @@ -24,14 +26,15 @@ public void OnTemperatureChanged(float newTemperature) } } - class Heater + public class Heater { public Heater(float temperature) { Temperature = temperature; } - // Cooler is activated when ambient temperature is higher than this + // Cooler is activated when ambient temperature + // is higher than this public float Temperature { get; set; } // Notifies that the temperature changed on this instance @@ -47,4 +50,5 @@ public void OnTemperatureChanged(float newTemperature) } } } + #endregion INCLUDE } \ No newline at end of file diff --git a/src/Chapter14/Listing14.02.DefiningTheEventPublsherThermostat.cs b/src/Chapter14/Listing14.02.DefiningTheEventPublsherThermostat.cs index 425119bec..cad221046 100644 --- a/src/Chapter14/Listing14.02.DefiningTheEventPublsherThermostat.cs +++ b/src/Chapter14/Listing14.02.DefiningTheEventPublsherThermostat.cs @@ -1,24 +1,14 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_02 { using System; - + #region INCLUDE public class Thermostat { - // Using C# 3.0 or later syntax. // Define the event publisher (initially without the sender) public Action? OnTemperatureChange { get; set; } - public float CurrentTemperature - { - get { return _CurrentTemperature; } - set - { - if(value != CurrentTemperature) - { - _CurrentTemperature = value; - } - } - } + public float CurrentTemperature { get; set; } + #endregion INCLUDE private float _CurrentTemperature; } } \ No newline at end of file diff --git a/src/Chapter14/Listing14.03.ConnectingThePublisherAndSubscribers.cs b/src/Chapter14/Listing14.03.ConnectingThePublisherAndSubscribers.cs index eec3056f5..3b17959de 100644 --- a/src/Chapter14/Listing14.03.ConnectingThePublisherAndSubscribers.cs +++ b/src/Chapter14/Listing14.03.ConnectingThePublisherAndSubscribers.cs @@ -1,10 +1,9 @@ -// TODO: Update listing in Manuscript -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_03 +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_03 { using System; using Listing14_01; using Listing14_02; - + #region INCLUDE public class Program { public static void Main() @@ -13,20 +12,23 @@ public static void Main() Heater heater = new Heater(60); Cooler cooler = new Cooler(80); - // Using C# 2.0 or later syntax + #region HIGHLIGHT thermostat.OnTemperatureChange += heater.OnTemperatureChanged; thermostat.OnTemperatureChange += cooler.OnTemperatureChanged; + #endregion HIGHLIGHT Console.Write("Enter temperature: "); string? temperature = Console.ReadLine(); if (!int.TryParse(temperature, out int currentTemperature)) { - Console.WriteLine($"'{temperature}' is not a valid integer."); + Console.WriteLine + ($"'{temperature}' is not a valid integer."); return; } thermostat.CurrentTemperature = currentTemperature; } } + #endregion INCLUDE } \ No newline at end of file diff --git a/src/Chapter14/Listing14.04.InvokingADelegateWithoutCheckingForNull.cs b/src/Chapter14/Listing14.04.InvokingADelegateWithoutCheckingForNull.cs index 2bcaeaa4d..a4be893fd 100644 --- a/src/Chapter14/Listing14.04.InvokingADelegateWithoutCheckingForNull.cs +++ b/src/Chapter14/Listing14.04.InvokingADelegateWithoutCheckingForNull.cs @@ -1,29 +1,39 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_04 { using System; - + #region INCLUDE public class Thermostat { + #region EXCLUDE // Define the event publisher public Action? OnTemperatureChange { get; set; } - + #endregion EXCLUDE public float CurrentTemperature { get { return _CurrentTemperature; } set { - if(value != CurrentTemperature) + #region HIGHLIGHT + if (value != CurrentTemperature) + #endregion HIGHLIGHT { + #region HIGHLIGHT _CurrentTemperature = value; + #endregion HIGHLIGHT // Call subscribers - // Justification: Incomplete, check for null needed. + // Incomplete, check for null needed + #region EXCLUDE #pragma warning disable CS8602 // Dereference of a possibly null reference. + #endregion EXCLUDE OnTemperatureChange(value); + #region EXCLUDE #pragma warning restore CS8602 // Dereference of a possibly null reference. + #endregion EXCLUDE } } } private float _CurrentTemperature; } + #endregion INCLUDE } \ No newline at end of file diff --git a/src/Chapter14/Listing14.05.InvokingADelegate.cs b/src/Chapter14/Listing14.05.InvokingADelegate.cs index 8af68a523..40177c9f8 100644 --- a/src/Chapter14/Listing14.05.InvokingADelegate.cs +++ b/src/Chapter14/Listing14.05.InvokingADelegate.cs @@ -1,7 +1,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_05 { using System; - + #region INCLUDE public class Thermostat { // Define the event publisher @@ -18,11 +18,14 @@ public float CurrentTemperature // If there are any subscribers, // notify them of changes in // temperature by invoking said subcribers + #region HIGHLIGHT OnTemperatureChange?.Invoke(value); // C# 6.0 + #endregion HIGHLIGHT } } } private float _CurrentTemperature; } + #endregion INCLUDE } \ No newline at end of file diff --git a/src/Chapter14/Listing14.06.InvokingADelegatePre6.cs b/src/Chapter14/Listing14.06.InvokingADelegatePre6.cs index e26adb9c9..4b3d0e545 100644 --- a/src/Chapter14/Listing14.06.InvokingADelegatePre6.cs +++ b/src/Chapter14/Listing14.06.InvokingADelegatePre6.cs @@ -1,7 +1,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_06 { using System; - + #region INCLUDE public class Thermostat { // Define the event publisher @@ -18,7 +18,10 @@ public float CurrentTemperature // If there are any subscribers, // notify them of changes in // temperature + #region EXCLUDE #pragma warning disable IDE1005 // Delegate invocation can be simplified. + #endregion EXCLUDE + #region HIGHLIGHT Action? localOnChange = OnTemperatureChange; if(localOnChange != null) @@ -26,11 +29,15 @@ public float CurrentTemperature // Call subscribers localOnChange(value); } + #endregion HIGHLIGHT + #region EXCLUDE #pragma warning restore IDE1005 // Delegate invocation can be simplified. + #endregion EXCLUDE } } } private float _CurrentTemperature; } + #endregion INCLUDE } \ No newline at end of file diff --git a/src/Chapter14/Listing14.07.UsingthePlusEqualsAndMinusEqualsDelegateOperators.cs b/src/Chapter14/Listing14.07.UsingthePlusEqualsAndMinusEqualsDelegateOperators.cs index 34f38868b..2f265a120 100644 --- a/src/Chapter14/Listing14.07.UsingthePlusEqualsAndMinusEqualsDelegateOperators.cs +++ b/src/Chapter14/Listing14.07.UsingthePlusEqualsAndMinusEqualsDelegateOperators.cs @@ -3,11 +3,13 @@ using System; using Listing14_01; using Listing14_05; - + #region INCLUDE + #region EXCLUDE public class Program { public static void Main() { + #endregion EXCLUDE Thermostat thermostat = new Thermostat(); Heater heater = new Heater(60); Cooler cooler = new Cooler(80); @@ -16,18 +18,24 @@ public static void Main() Action delegate2; Action? delegate3; - // use Constructor syntax for C# 1.0 delegate1 = heater.OnTemperatureChanged; delegate2 = cooler.OnTemperatureChanged; Console.WriteLine("Invoke both delegates:"); delegate3 = delegate1; + #region HIGHLIGHT delegate3 += delegate2; + #endregion HIGHLIGHT delegate3(90); Console.WriteLine("Invoke only delegate2"); + #region HIGHLIGHT delegate3 -= delegate1; + #endregion HIGHLIGHT delegate3!(30); + #region EXCLUDE } } + #endregion EXCLUDE + #endregion INCLUDE } \ No newline at end of file diff --git a/src/Chapter14/Listing14.08.UsingThePlusAndMinusDelegateOperators.cs b/src/Chapter14/Listing14.08.UsingThePlusAndMinusDelegateOperators.cs index 321b4a4bd..c727ffe11 100644 --- a/src/Chapter14/Listing14.08.UsingThePlusAndMinusDelegateOperators.cs +++ b/src/Chapter14/Listing14.08.UsingThePlusAndMinusDelegateOperators.cs @@ -3,11 +3,13 @@ using System; using Listing14_01; using Listing14_05; - + #region INCLUDE + #region EXCLUDE public class Program { public static void Main() { + #endregion EXCLUDE Thermostat thermostat = new Thermostat(); Heater heater = new Heater(60); Cooler cooler = new Cooler(80); @@ -22,12 +24,19 @@ public static void Main() delegate2 = cooler.OnTemperatureChanged; Console.WriteLine("Combine delegates using + operator:"); + #region HIGHLIGHT delegate3 = delegate1 + delegate2; + #endregion HIGHLIGHT delegate3(60); Console.WriteLine("Uncombine delegates using - operator:"); + #region HIGHLIGHT delegate3 = (delegate3 - delegate2)!; + #endregion HIGHLIGHT delegate3(60); + #region EXCLUDE } } + #endregion EXCLUDE + #endregion INCLUDE } \ No newline at end of file diff --git a/src/Chapter14/Listing14.09.OnTemperatureChangedThrowingAnException.cs b/src/Chapter14/Listing14.09.OnTemperatureChangedThrowingAnException.cs index d3e48e851..5eeb1b62a 100644 --- a/src/Chapter14/Listing14.09.OnTemperatureChangedThrowingAnException.cs +++ b/src/Chapter14/Listing14.09.OnTemperatureChangedThrowingAnException.cs @@ -1,10 +1,9 @@ -// TODO: Update listing in Manuscript -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_09 +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_09 { using System; using Listing14_01; using Listing14_05; - + #region INCLUDE public class Program { public static void Main() @@ -13,16 +12,15 @@ public static void Main() Heater heater = new Heater(60); Cooler cooler = new Cooler(80); - // Using C# 2.0 or later syntax thermostat.OnTemperatureChange += heater.OnTemperatureChanged; - // Using C# 3.0. Change to anonymous method - // if using C# 2.0 + #region HIGHLIGHT thermostat.OnTemperatureChange += (newTemperature) => { throw new InvalidOperationException(); }; + #endregion HIGHLIGHT thermostat.OnTemperatureChange += cooler.OnTemperatureChanged; @@ -30,10 +28,12 @@ public static void Main() string? temperature = Console.ReadLine(); if (!int.TryParse(temperature, out int currentTemperature)) { - Console.WriteLine($"'{temperature}' is not a valid integer."); + Console.WriteLine + ($"'{temperature}' is not a valid integer."); return; } thermostat.CurrentTemperature = currentTemperature; } } + #endregion HIGHLIGHT } \ No newline at end of file diff --git a/src/Chapter14/Listing14.10.HandlingExceptionsFromSubscribers.cs b/src/Chapter14/Listing14.10.HandlingExceptionsFromSubscribers.cs index fb8fff91b..0a9182bdf 100644 --- a/src/Chapter14/Listing14.10.HandlingExceptionsFromSubscribers.cs +++ b/src/Chapter14/Listing14.10.HandlingExceptionsFromSubscribers.cs @@ -1,13 +1,11 @@ -// TODO: Update listing in Manuscript -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_10 +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_10 { using System; using System.Collections.Generic; using Listing14_01; - + #region INCLUDE public class Thermostat { - // Using C# 3.0 or later syntax // Define the event publisher public Action? OnTemperatureChange; @@ -19,9 +17,11 @@ public float CurrentTemperature if(value != CurrentTemperature) { _CurrentTemperature = value; - Action? onTemperatureChange = OnTemperatureChange; + Action? + onTemperatureChange = OnTemperatureChange; if (onTemperatureChange != null) { + #region HIGHLIGHT List exceptionCollection = new List(); foreach( @@ -44,12 +44,14 @@ Delegate handler in "OnTemperatureChange Event subscribers.", exceptionCollection); } + #endregion HIGHLIGHT } } } } private float _CurrentTemperature; } + #endregion INCLUDE public class Program { diff --git a/src/Chapter14/Listing14.11.UsingTheAssignmentOperationRatherThanPlusEquals.cs b/src/Chapter14/Listing14.11.UsingTheAssignmentOperationRatherThanPlusEquals.cs index d0e4441dd..397722032 100644 --- a/src/Chapter14/Listing14.11.UsingTheAssignmentOperationRatherThanPlusEquals.cs +++ b/src/Chapter14/Listing14.11.UsingTheAssignmentOperationRatherThanPlusEquals.cs @@ -1,11 +1,10 @@ -// TODO: Update listing in Manuscript -using AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_02; +using AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_02; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_11 { using System; using Listing14_01; - + #region INCLUDE public class Program { public static void Main() @@ -14,24 +13,26 @@ public static void Main() Heater heater = new Heater(60); Cooler cooler = new Cooler(80); - // Note: Use new Action(cooler.OnTemperatureChanged) - // for C# 1.0 syntax thermostat.OnTemperatureChange = heater.OnTemperatureChanged; // Bug: Assignment operator overrides // previous assignment + #region HIGHLIGHT thermostat.OnTemperatureChange = cooler.OnTemperatureChanged; + #endregion HIGHLIGHT Console.Write("Enter temperature: "); string? temperature = Console.ReadLine(); if (!int.TryParse(temperature, out int currentTemperature)) { - Console.WriteLine($"'{temperature}' is not a valid integer."); + Console.WriteLine + ($"'{temperature}' is not a valid integer."); return; } thermostat.CurrentTemperature = currentTemperature; } } + #endregion INCLUDE } \ No newline at end of file diff --git a/src/Chapter14/Listing14.12.FiringTheEventFromOutsideTheEventContainer.cs b/src/Chapter14/Listing14.12.FiringTheEventFromOutsideTheEventContainer.cs index 79e73f662..9c060eccf 100644 --- a/src/Chapter14/Listing14.12.FiringTheEventFromOutsideTheEventContainer.cs +++ b/src/Chapter14/Listing14.12.FiringTheEventFromOutsideTheEventContainer.cs @@ -2,7 +2,7 @@ { using Listing14_01; using Listing14_10; - + #region INCLUDE public class Program { public static void Main() @@ -11,8 +11,6 @@ public static void Main() Heater heater = new Heater(60); Cooler cooler = new Cooler(80); - // Note: Use new Action(cooler.OnTemperatureChanged) - // for C# 1.0 syntax thermostat.OnTemperatureChange += heater.OnTemperatureChanged; @@ -20,7 +18,10 @@ public static void Main() cooler.OnTemperatureChanged; // Bug: Should not be allowed + #region HIGHLIGHT thermostat.OnTemperatureChange(42); + #endregion HIGHLIGHT } } + #endregion INCLUDE } \ No newline at end of file diff --git a/src/Chapter14/Listing14.13.UsingTheEventKeywordWithTheEventCodingPattern.cs b/src/Chapter14/Listing14.13.UsingTheEventKeywordWithTheEventCodingPattern.cs index 016f2aaf8..e8e2372df 100644 --- a/src/Chapter14/Listing14.13.UsingTheEventKeywordWithTheEventCodingPattern.cs +++ b/src/Chapter14/Listing14.13.UsingTheEventKeywordWithTheEventCodingPattern.cs @@ -2,9 +2,10 @@ { using System; #pragma warning disable 67 // OnTemperatureChange is declared but never used - + #region INCLUDE public class Thermostat { + #region HIGHLIGHT public class TemperatureArgs : System.EventArgs { public TemperatureArgs(float newTemperature) @@ -18,13 +19,17 @@ public TemperatureArgs(float newTemperature) // Define the event publisher public event EventHandler OnTemperatureChange = delegate { }; + #endregion HIGHLIGHT public float CurrentTemperature + #region EXCLUDE { get { return _CurrentTemperature; } set { _CurrentTemperature = value; } } + #endregion EXCLUDE private float _CurrentTemperature; } + #endregion INCLUDE #pragma warning restore 67 } \ No newline at end of file diff --git a/src/Chapter14/Listing14.14.DeclaringAGenericDelegateType.cs b/src/Chapter14/Listing14.14.DeclaringAGenericDelegateType.cs index 6547ef1e8..f4ddfaa74 100644 --- a/src/Chapter14/Listing14.14.DeclaringAGenericDelegateType.cs +++ b/src/Chapter14/Listing14.14.DeclaringAGenericDelegateType.cs @@ -4,7 +4,10 @@ public class Thermostat { - public delegate void EventHandler(object sender, TEventArgs e) + #region INCLUDE + public delegate void EventHandler( + object sender, TEventArgs e) + #endregion INCLUDE where TEventArgs : EventArgs; } } \ No newline at end of file diff --git a/src/Chapter14/Listing14.15.FiringTheEventNotification.cs b/src/Chapter14/Listing14.15.FiringTheEventNotification.cs index 7f10f4bfa..d147e2089 100644 --- a/src/Chapter14/Listing14.15.FiringTheEventNotification.cs +++ b/src/Chapter14/Listing14.15.FiringTheEventNotification.cs @@ -1,8 +1,9 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_15 { using System; - + #region INCLUDE public class Thermostat + #region EXCLUDE { public class TemperatureArgs : System.EventArgs { @@ -17,6 +18,7 @@ public TemperatureArgs(float newTemperature) // Define the event publisher public event EventHandler OnTemperatureChange = delegate { }; + #endregion EXCLUDE public float CurrentTemperature { @@ -29,11 +31,14 @@ public float CurrentTemperature // If there are any subscribers, // notify them of changes in // temperature by invoking said subcribers + #region HIGHLIGHT OnTemperatureChange?.Invoke( // C# 6.0 this, new TemperatureArgs(value)); + #endregion HIGHLIGHT } } } private float _CurrentTemperature; } + #endregion INCLUDE } \ No newline at end of file diff --git a/src/Chapter14/Listing14.16.UsingCustomDelegateType.cs b/src/Chapter14/Listing14.16.UsingCustomDelegateType.cs index 701f87c95..388fcedc8 100644 --- a/src/Chapter14/Listing14.16.UsingCustomDelegateType.cs +++ b/src/Chapter14/Listing14.16.UsingCustomDelegateType.cs @@ -1,5 +1,6 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_16 { + #region INCLUDE public class Thermostat { public class TemperatureArgs : System.EventArgs @@ -9,21 +10,19 @@ public TemperatureArgs(float newTemperature) NewTemperature = newTemperature; } - public float NewTemperature - { - get { return _NewTemperature; } - set { _NewTemperature = value; } - } - private float _NewTemperature; + public float NewTemperature { get; set; } } + #region HIGHLIGHT public delegate void TemperatureChangeHandler( object sender, TemperatureArgs newTemperature); public event TemperatureChangeHandler? OnTemperatureChange; + #endregion HIGHLIGHT public float CurrentTemperature + #region EXCLUDE { get { return _CurrentTemperature; } set @@ -40,6 +39,8 @@ public float CurrentTemperature } } } + #endregion EXCLUDE private float _CurrentTemperature; } + #endregion INCLUDE } \ No newline at end of file diff --git a/src/Chapter14/Listing14.17.DeclaringTheOnTemperatureChangeEvent.cs b/src/Chapter14/Listing14.17.DeclaringTheOnTemperatureChangeEvent.cs index a6fff4af3..7b86a5a47 100644 --- a/src/Chapter14/Listing14.17.DeclaringTheOnTemperatureChangeEvent.cs +++ b/src/Chapter14/Listing14.17.DeclaringTheOnTemperatureChangeEvent.cs @@ -5,9 +5,10 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_17 { using System; -// In an actual implementation we would utilize this event - + // In an actual implementation we would utilize this event + #region INCLUDE public class Thermostat + #region EXCLUDE { public class TemperatureArgs : System.EventArgs { @@ -18,7 +19,8 @@ public TemperatureArgs(float newTemperature) public float NewTemperature { get; set; } } - + #endregion EXCLUDE public event EventHandler? OnTemperatureChange; } + #endregion INCLUDE } \ No newline at end of file diff --git a/src/Chapter14/Listing14.18.CSharpConceptualEquivalentOfEventCILCode.cs b/src/Chapter14/Listing14.18.CSharpConceptualEquivalentOfEventCILCode.cs index f64c0ea41..5a90322e3 100644 --- a/src/Chapter14/Listing14.18.CSharpConceptualEquivalentOfEventCILCode.cs +++ b/src/Chapter14/Listing14.18.CSharpConceptualEquivalentOfEventCILCode.cs @@ -6,8 +6,9 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_18 { using System; - + #region INCLUDE public class Thermostat + #region EXCLUDE { // Used to suppress warning CS0469: field never assigned to, and // will always have its default value null. @@ -17,6 +18,7 @@ public Thermostat(EventHandler? onTemperatureChange) } // ... + #endregion EXCLUDE // Declaring the delegate field to save the // list of subscribers private EventHandler? _OnTemperatureChange; @@ -33,19 +35,22 @@ public void remove_OnTemperatureChange( System.Delegate.Remove(_OnTemperatureChange, handler); } - //public event EventHandler OnTemperatureChange - //{ - // //Would cause a compiler error - // add - // { - // add_OnTemperatureChange(value); - // } - // //Would cause a compiler error - // remove - // { - // remove_OnTemperatureChange(value); - // } - //} + #if ConceptulEquivalendCode + public event EventHandler OnTemperatureChange + { + //Would cause a compiler error + add + { + add_OnTemperatureChange(value); + } + //Would cause a compiler error + remove + { + remove_OnTemperatureChange(value); + } + } + #endif // ConceptulEquivalendCode + #endregion INCLUDE public class TemperatureArgs : System.EventArgs { diff --git a/src/Chapter14/Listing14.19.CustomAddAndRemoveHandlers.cs b/src/Chapter14/Listing14.19.CustomAddAndRemoveHandlers.cs index 95d4997f9..61ca241d0 100644 --- a/src/Chapter14/Listing14.19.CustomAddAndRemoveHandlers.cs +++ b/src/Chapter14/Listing14.19.CustomAddAndRemoveHandlers.cs @@ -1,8 +1,10 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_19 { + #region INCLUDE public class Thermostat { public class TemperatureArgs : System.EventArgs + #region EXCLUDE { public TemperatureArgs(float newTemperature) { @@ -11,27 +13,33 @@ public TemperatureArgs(float newTemperature) public float NewTemperature { get; set; } } - + // Define the delegate data type - public delegate void TemperatureChangeHandler( + public delegate void EventHandler( object sender, TemperatureArgs newTemperature); - + #endregion EXCLUDE + #region HIGHLIGHT // Define the event publisher - public event TemperatureChangeHandler OnTemperatureChange + public event EventHandler OnTemperatureChange { add { - _OnTemperatureChange = (TemperatureChangeHandler)System.Delegate.Combine(value, _OnTemperatureChange); + _OnTemperatureChange = + (EventHandler)System.Delegate.Combine + (value, _OnTemperatureChange); } remove { _OnTemperatureChange = - (TemperatureChangeHandler?)System.Delegate.Remove(_OnTemperatureChange, value); + (EventHandler?)System.Delegate.Remove + (_OnTemperatureChange, value); } } - protected TemperatureChangeHandler? _OnTemperatureChange; + protected EventHandler? _OnTemperatureChange; + #endregion HIGHLIGHT public float CurrentTemperature + #region EXCLUDE { set { @@ -47,6 +55,8 @@ public float CurrentTemperature } get { return _CurrentTemperature; } } + #endregion EXCLUDE private float _CurrentTemperature; } + #endregion INCLUDE } \ No newline at end of file diff --git a/src/Chapter15/Listing15.01.CollectionInitialization.cs b/src/Chapter15/Listing15.01.CollectionInitialization.cs index 60cd50483..63710d3fa 100644 --- a/src/Chapter15/Listing15.01.CollectionInitialization.cs +++ b/src/Chapter15/Listing15.01.CollectionInitialization.cs @@ -1,5 +1,6 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_01 { + #region INCLUDE using System; using System.Collections.Generic; @@ -31,4 +32,5 @@ private static void Print(IEnumerable items) } } } + #endregion INCLUDE } diff --git a/src/Chapter15/Listing15.02.DictionaryInitializers.cs b/src/Chapter15/Listing15.02.DictionaryInitializers.cs index 97746dcd5..6077961c7 100644 --- a/src/Chapter15/Listing15.02.DictionaryInitializers.cs +++ b/src/Chapter15/Listing15.02.DictionaryInitializers.cs @@ -1,12 +1,14 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_02 { + #region INCLUDE using System; using System.Collections.Generic; - + #region EXCLUDE public class Program { public static void Main() { + #endregion EXCLUDE #if !PRECSHARP6 Dictionary colorMap = new Dictionary @@ -26,6 +28,7 @@ public static void Main() {"Verbose", ConsoleColor.White} }; #endif + #endregion INCLUDE Print(colorMap); } diff --git a/src/Chapter15/Listing15.03.ForeachWithArrays.cs b/src/Chapter15/Listing15.03.ForeachWithArrays.cs index 165915d71..234c9b700 100644 --- a/src/Chapter15/Listing15.03.ForeachWithArrays.cs +++ b/src/Chapter15/Listing15.03.ForeachWithArrays.cs @@ -6,12 +6,14 @@ public class Program { public static void Main() { + #region INCLUDE int[] array = new int[] { 1, 2, 3, 4, 5, 6 }; foreach(int item in array) { Console.WriteLine(item); } + #endregion INCLUDE } } } diff --git a/src/Chapter15/Listing15.04.CompiledImplementationOfForeachWithArrays.cs b/src/Chapter15/Listing15.04.CompiledImplementationOfForeachWithArrays.cs index d8105c0c6..4325dc0df 100644 --- a/src/Chapter15/Listing15.04.CompiledImplementationOfForeachWithArrays.cs +++ b/src/Chapter15/Listing15.04.CompiledImplementationOfForeachWithArrays.cs @@ -6,6 +6,7 @@ public class Program { public static void Main() { + #region INCLUDE int[] tempArray; int[] array = new int[] { 1, 2, 3, 4, 5, 6 }; @@ -16,6 +17,7 @@ public static void Main() Console.WriteLine(item); } + #endregion INCLUDE } } } diff --git a/src/Chapter15/Listing15.05.IteratingOverACollectionUsingWhile.cs b/src/Chapter15/Listing15.05.IteratingOverACollectionUsingWhile.cs index ad6350aca..0bfee2ac4 100644 --- a/src/Chapter15/Listing15.05.IteratingOverACollectionUsingWhile.cs +++ b/src/Chapter15/Listing15.05.IteratingOverACollectionUsingWhile.cs @@ -6,12 +6,24 @@ public class Program { public static void Main() { + #region INCLUDE System.Collections.Generic.Stack stack = new System.Collections.Generic.Stack(); int number; // ... // This code is conceptual, not the actual code + #if ConceptualCode + while(stack.MoveNext()) + { + number = stack.Current(); + Console.WriteLine(number); + } + #endif // ConceptualCode + + #endregion INCLUDE + + // Actual Code while(stack.Pop() != -1) //this is actually not the right logic, but the point is the while, not stack { number = stack.Peek(); diff --git a/src/Chapter15/Listing15.06.ASeparateEnumeratorMaintainingStateDuringAnIteration.cs b/src/Chapter15/Listing15.06.ASeparateEnumeratorMaintainingStateDuringAnIteration.cs index efa2d3874..6352b15a3 100644 --- a/src/Chapter15/Listing15.06.ASeparateEnumeratorMaintainingStateDuringAnIteration.cs +++ b/src/Chapter15/Listing15.06.ASeparateEnumeratorMaintainingStateDuringAnIteration.cs @@ -6,6 +6,7 @@ public class Program { public static void Main() { + #region INCLUDE System.Collections.Generic.Stack stack = new System.Collections.Generic.Stack(); int number; @@ -23,6 +24,7 @@ public static void Main() number = enumerator.Current; Console.WriteLine(number); } + #endregion INCLUDE } } } diff --git a/src/Chapter15/Listing15.07.CompiledResultOfForeachOnCollections.cs b/src/Chapter15/Listing15.07.CompiledResultOfForeachOnCollections.cs index 0ec3c2689..367390976 100644 --- a/src/Chapter15/Listing15.07.CompiledResultOfForeachOnCollections.cs +++ b/src/Chapter15/Listing15.07.CompiledResultOfForeachOnCollections.cs @@ -6,6 +6,7 @@ public class Program { public static void Main() { + #region INCLUDE System.Collections.Generic.Stack stack = new System.Collections.Generic.Stack(); System.Collections.Generic.Stack.Enumerator enumerator; @@ -35,6 +36,7 @@ public static void Main() // disposable.Dispose(); // } } + #endregion INCLUDE } } } diff --git a/src/Chapter15/Listing15.08.ErrorHandlingAndResourceCleanupWithUsing.cs b/src/Chapter15/Listing15.08.ErrorHandlingAndResourceCleanupWithUsing.cs index eddc670ee..4de6f3bbc 100644 --- a/src/Chapter15/Listing15.08.ErrorHandlingAndResourceCleanupWithUsing.cs +++ b/src/Chapter15/Listing15.08.ErrorHandlingAndResourceCleanupWithUsing.cs @@ -6,20 +6,24 @@ public class Program { public static void Main() { + #region INCLUDE System.Collections.Generic.Stack stack = new System.Collections.Generic.Stack(); int number; - using( + #region HIGHLIGHT + using ( System.Collections.Generic.Stack.Enumerator enumerator = stack.GetEnumerator()) + #endregion HIGHLIGHT { - while(enumerator.MoveNext()) + while (enumerator.MoveNext()) { number = enumerator.Current; Console.WriteLine(number); } } + #endregion INCLUDE } } } diff --git a/src/Chapter15/Listing15.10.FilteringWithSystem.Linq.Enumerable.Where.cs b/src/Chapter15/Listing15.10.FilteringWithSystem.Linq.Enumerable.Where.cs index 1c813b46c..f42508714 100644 --- a/src/Chapter15/Listing15.10.FilteringWithSystem.Linq.Enumerable.Where.cs +++ b/src/Chapter15/Listing15.10.FilteringWithSystem.Linq.Enumerable.Where.cs @@ -1,6 +1,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_10 { using AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15; + #region INCLUDE using System; using System.Collections.Generic; using System.Linq; @@ -10,10 +11,13 @@ public class Program public static void Main() { IEnumerable patents = PatentData.Patents; + #region HIGHLIGHT patents = patents.Where( patent => patent.YearOfPublication.StartsWith("18")); + #endregion HIGHLIGHT Print(patents); } + #region EXCLUDE private static void Print(IEnumerable items) { @@ -22,5 +26,7 @@ private static void Print(IEnumerable items) Console.WriteLine(item); } } + #endregion EXCLUDE } + #endregion INCLUDE } diff --git a/src/Chapter15/Listing15.11.ProjectionWithSystem.Linq.Enumerable.Select.cs b/src/Chapter15/Listing15.11.ProjectionWithSystem.Linq.Enumerable.Select.cs index 21d477fde..ef7e79647 100644 --- a/src/Chapter15/Listing15.11.ProjectionWithSystem.Linq.Enumerable.Select.cs +++ b/src/Chapter15/Listing15.11.ProjectionWithSystem.Linq.Enumerable.Select.cs @@ -1,6 +1,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_11 { using AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15; + #region INCLUDE using System; using System.Collections.Generic; using System.Linq; @@ -12,11 +13,14 @@ public static void Main() IEnumerable patents = PatentData.Patents; IEnumerable patentsOf1800 = patents.Where( patent => patent.YearOfPublication.StartsWith("18")); + #region HIGHLIGHT IEnumerable items = patentsOf1800.Select( patent => patent.ToString()); + #endregion HIGHLIGHT Print(items); } + #region EXCLUDE private static void Print(IEnumerable items) { @@ -25,5 +29,7 @@ private static void Print(IEnumerable items) Console.WriteLine(item); } } + #endregion EXCLUDE } + #endregion INCLUDE } diff --git a/src/Chapter15/Listing15.12.ProjectionWithSystem.Linq.Enumerable.Select.cs b/src/Chapter15/Listing15.12.ProjectionWithSystem.Linq.Enumerable.Select.cs index b0b766144..6f638234c 100644 --- a/src/Chapter15/Listing15.12.ProjectionWithSystem.Linq.Enumerable.Select.cs +++ b/src/Chapter15/Listing15.12.ProjectionWithSystem.Linq.Enumerable.Select.cs @@ -11,12 +11,14 @@ public static void Main() { string rootDirectory = Directory.GetCurrentDirectory(); string searchPattern = "*"; ; - + #region INCLUDE + //... IEnumerable fileList = Directory.EnumerateFiles( rootDirectory, searchPattern); IEnumerable files = fileList.Select( file => new FileInfo(file)); - + //... + #endregion INCLUDE Print(files); } diff --git a/src/Chapter15/Listing15.13.ProjectionToATuple.cs b/src/Chapter15/Listing15.13.ProjectionToATuple.cs index 5c85a7e37..92778cf03 100644 --- a/src/Chapter15/Listing15.13.ProjectionToATuple.cs +++ b/src/Chapter15/Listing15.13.ProjectionToATuple.cs @@ -3,17 +3,17 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_13 using System; using System.Collections.Generic; using System.IO; - using System.Linq; - public class Program { public static void Main() { string rootDirectory = Directory.GetCurrentDirectory(); string searchPattern = "*"; - + #region INCLUDE + //... IEnumerable fileList = Directory.EnumerateFiles( - rootDirectory, searchPattern); + rootDirectory, searchPattern); + #region HIGHLIGHT IEnumerable<(string FileName, long Size)> items = fileList.Select( file => { @@ -23,8 +23,8 @@ public static void Main() Size: fileInfo.Length ); }); - - + //... + #endregion INCLUDE Print(items); } diff --git a/src/Chapter15/Listing15.14.ExecutingLinqQueriesInParallel.cs b/src/Chapter15/Listing15.14.ExecutingLinqQueriesInParallel.cs index 3b92ec443..cfdad9bc2 100644 --- a/src/Chapter15/Listing15.14.ExecutingLinqQueriesInParallel.cs +++ b/src/Chapter15/Listing15.14.ExecutingLinqQueriesInParallel.cs @@ -11,10 +11,13 @@ public static void Main() { string rootDirectory = Directory.GetCurrentDirectory(); string searchPattern = "*"; - - IEnumerable fileList = Directory.GetFiles( + #region INCLUDE + //... + IEnumerable fileList = Directory.EnumerateFiles( rootDirectory, searchPattern); + #region HIGHLIGHT var items = fileList.AsParallel().Select( + #endregion HIGHLIGHT file => { FileInfo fileInfo = new FileInfo(file); @@ -24,10 +27,13 @@ public static void Main() Size = fileInfo.Length }; }); + //... + #endregion INCLUDE Print(items); } + private static void Print(IEnumerable items) { foreach(T item in items) diff --git a/src/Chapter15/Listing15.15.CountingItemsWithCount.cs b/src/Chapter15/Listing15.15.CountingItemsWithCount.cs index c3507ae3f..1d5af52c6 100644 --- a/src/Chapter15/Listing15.15.CountingItemsWithCount.cs +++ b/src/Chapter15/Listing15.15.CountingItemsWithCount.cs @@ -1,6 +1,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_15 { using AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15; + #region INCLUDE using System; using System.Collections.Generic; using System.Linq; @@ -10,11 +11,13 @@ public class Program public static void Main() { IEnumerable patents = PatentData.Patents; + #region HIGHLIGHT Console.WriteLine($"Patent Count: { patents.Count() }"); - Console.WriteLine($@"Patent Count in 1800s: { + #endregion HIGHLIGHT + Console.WriteLine($@"Patent Count in 1800s: { patents.Count(patent => - patent.YearOfPublication.StartsWith("18")) - }"); + patent.YearOfPublication.StartsWith("18"))}"); + #endregion INCLUDE } } } diff --git a/src/Chapter15/Listing15.16.FilteringWithSystem.Linq.Enumerable.Where.cs b/src/Chapter15/Listing15.16.FilteringWithSystem.Linq.Enumerable.Where.cs index 6b078938b..f4876b620 100644 --- a/src/Chapter15/Listing15.16.FilteringWithSystem.Linq.Enumerable.Where.cs +++ b/src/Chapter15/Listing15.16.FilteringWithSystem.Linq.Enumerable.Where.cs @@ -1,14 +1,17 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_16 { using AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15; + #region INCLUDE using System; using System.Collections.Generic; using System.Linq; + #region EXCLUDE public class Program { public static void Main() { + #endregion EXCLUDE IEnumerable patents = PatentData.Patents; bool result; patents = patents.Where( @@ -46,6 +49,9 @@ public static void Main() Console.Write(" There are "); Console.WriteLine( $"{ patents.Count() } patents prior to 1900."); + + //... + #endregion INCLUDE } } } diff --git a/src/Chapter15/Listing15.17.OrderingWithSystem.Linq.Enumerable.OrderByAndThenBy.cs b/src/Chapter15/Listing15.17.OrderingWithSystem.Linq.Enumerable.OrderByAndThenBy.cs index 6dff2aa21..f451bc2ba 100644 --- a/src/Chapter15/Listing15.17.OrderingWithSystem.Linq.Enumerable.OrderByAndThenBy.cs +++ b/src/Chapter15/Listing15.17.OrderingWithSystem.Linq.Enumerable.OrderByAndThenBy.cs @@ -1,14 +1,16 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_17 { using AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15; + #region INCLUDE using System; using System.Collections.Generic; using System.Linq; - + #region EXCLUDE public class Program { public static void Main() { + #endregion EXCLUDE IEnumerable items; Patent[] patents = PatentData.Patents; items = patents.OrderBy( @@ -23,6 +25,9 @@ public static void Main() .ThenByDescending( patent => patent.Title); Print(items); + + //... + #endregion INCLUDE } private static void Print(IEnumerable items) diff --git a/src/Chapter15/Listing15.19.AnInnerJoinUsingSystem.Linq.Enumerable.Join.cs b/src/Chapter15/Listing15.19.AnInnerJoinUsingSystem.Linq.Enumerable.Join.cs index 7f850962e..57ad4eb29 100644 --- a/src/Chapter15/Listing15.19.AnInnerJoinUsingSystem.Linq.Enumerable.Join.cs +++ b/src/Chapter15/Listing15.19.AnInnerJoinUsingSystem.Linq.Enumerable.Join.cs @@ -1,18 +1,20 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_19 { using AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15; + #region INCLUDE using System; using System.Collections.Generic; using System.Linq; - + #region EXCLUDE public class Program { public static void Main() { + #endregion EXCLUDE Department[] departments = CorporateData.Departments; Employee[] employees = CorporateData.Employees; - IEnumerable<(int Id, string Name, string Title, + IEnumerable<(int Id, string Name, string Title, Department Department)> items = employees.Join( departments, @@ -26,12 +28,16 @@ public static void Main() )); - foreach ((int Id, string Name, string Title, Department Department) item in items) + foreach + ((int Id, string Name, string Title, + Department Department) item in items) { Console.WriteLine( - $"{ item.Name } ({ item.Title })"); + $"{item.Name} ({item.Title})"); Console.WriteLine("\t" + item.Department); } } + //... + #endregion INCLUDE } } diff --git a/src/Chapter15/Listing15.20.AnotherInnerJoinWithSystem.Linq.Enumerable.Join.cs b/src/Chapter15/Listing15.20.AnotherInnerJoinWithSystem.Linq.Enumerable.Join.cs index 36c6f99a7..214b0b76f 100644 --- a/src/Chapter15/Listing15.20.AnotherInnerJoinWithSystem.Linq.Enumerable.Join.cs +++ b/src/Chapter15/Listing15.20.AnotherInnerJoinWithSystem.Linq.Enumerable.Join.cs @@ -1,14 +1,17 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_20 { using AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15; + #region INCLUDE using System; using System.Collections.Generic; using System.Linq; + #region EXCLUDE public class Program { public static void Main() { + #endregion EXCLUDE Department[] departments = CorporateData.Departments; Employee[] employees = CorporateData.Employees; @@ -24,12 +27,14 @@ public static void Main() ); - foreach ((long Id, string Name, Employee Employee) item in items) + foreach + ((long Id, string Name, Employee Employee) item in items) { Console.WriteLine(item.Name); Console.WriteLine("\t" + item.Employee); } - + //... + #endregion INCLUDE } } } diff --git a/src/Chapter15/Listing15.21.GroupingItemsTogetherUsingSystem.Linq.Enumerable.GroupBy.cs b/src/Chapter15/Listing15.21.GroupingItemsTogetherUsingSystem.Linq.Enumerable.GroupBy.cs index e2ec9fe3e..bc3cfd87d 100644 --- a/src/Chapter15/Listing15.21.GroupingItemsTogetherUsingSystem.Linq.Enumerable.GroupBy.cs +++ b/src/Chapter15/Listing15.21.GroupingItemsTogetherUsingSystem.Linq.Enumerable.GroupBy.cs @@ -1,14 +1,16 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_21 { using AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15; + #region INCLUDE using System; using System.Collections.Generic; using System.Linq; - + #region EXCLUDE public class Program { public static void Main() { + #endregion EXCLUDE IEnumerable employees = CorporateData.Employees; IEnumerable> groupedEmployees = @@ -25,7 +27,8 @@ public static void Main() Console.WriteLine( "\tCount: " + employeeGroup.Count()); } - + //... + #endregion INCLUDE } } } diff --git a/src/Chapter15/Listing15.22.CreatingAChildCollectionWithSystem.Linq.Enumerable.GroupJoin.cs b/src/Chapter15/Listing15.22.CreatingAChildCollectionWithSystem.Linq.Enumerable.GroupJoin.cs index 936b12a32..b1af44a44 100644 --- a/src/Chapter15/Listing15.22.CreatingAChildCollectionWithSystem.Linq.Enumerable.GroupJoin.cs +++ b/src/Chapter15/Listing15.22.CreatingAChildCollectionWithSystem.Linq.Enumerable.GroupJoin.cs @@ -1,18 +1,23 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_22 { using AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15; + #region INCLUDE using System; using System.Collections.Generic; using System.Linq; + #region EXCLUDE public class Program { public static void Main() { + #endregion EXCLUDE Department[] departments = CorporateData.Departments; Employee[] employees = CorporateData.Employees; - IEnumerable<(long Id, string Name, IEnumerable Employees)> items = + IEnumerable< + (long Id, string Name, IEnumerable Employees)> + items = departments.GroupJoin( employees, department => department.Id, @@ -23,7 +28,9 @@ public static void Main() departmentEmployees )); - foreach ((_, string name, IEnumerable employeeCollection) in items) + foreach ( + (_, string name, IEnumerable employeeCollection) + in items) { Console.WriteLine(name); foreach (Employee employee in employeeCollection) @@ -31,6 +38,8 @@ public static void Main() Console.WriteLine("\t" + employee); } } + //... + #endregion INCLUDE } } } diff --git a/src/Chapter15/Listing15.23.ImplementingAnOuterJoinUsingGroupJoinWithSelectMany.cs b/src/Chapter15/Listing15.23.ImplementingAnOuterJoinUsingGroupJoinWithSelectMany.cs index 8adc433b0..7b94d1f63 100644 --- a/src/Chapter15/Listing15.23.ImplementingAnOuterJoinUsingGroupJoinWithSelectMany.cs +++ b/src/Chapter15/Listing15.23.ImplementingAnOuterJoinUsingGroupJoinWithSelectMany.cs @@ -1,13 +1,16 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_23 { using AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15; + #region INCLUDE using System; using System.Linq; + #region EXCLUDE public class Program { public static void Main() { + #endregion EXCLUDE Department[] departments = CorporateData.Departments; Employee[] employees = CorporateData.Employees; @@ -38,6 +41,8 @@ public static void Main() Console.WriteLine("\t" + employee); } } + //... + #endregion INCLUDE } } } diff --git a/src/Chapter15/Listing15.24.CallingSelectMany.cs b/src/Chapter15/Listing15.24.CallingSelectMany.cs index 087f8bfb6..f8b61b268 100644 --- a/src/Chapter15/Listing15.24.CallingSelectMany.cs +++ b/src/Chapter15/Listing15.24.CallingSelectMany.cs @@ -1,14 +1,17 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_24 { + #region INCLUDE using System; using System.Collections.Generic; using System.Linq; - + #region EXCLUDE public class Program { public static void Main() { - (string Team, string[] Players)[] worldCup2006Finalists = new[] + #endregion EXCLUDE + (string Team, string[] Players) + [] worldCup2006Finalists = new[] { ( TeamName: "France", @@ -53,7 +56,8 @@ public static void Main() team => team.Players); Print(players); - + //... + #endregion INCLUDE } private static void Print(IEnumerable items) diff --git a/src/Chapter15/Listing15.25.MoreSystem.Linq.EnumerableMethodCalls.cs b/src/Chapter15/Listing15.25.MoreSystem.Linq.EnumerableMethodCalls.cs index 4288468a1..b89442cc4 100644 --- a/src/Chapter15/Listing15.25.MoreSystem.Linq.EnumerableMethodCalls.cs +++ b/src/Chapter15/Listing15.25.MoreSystem.Linq.EnumerableMethodCalls.cs @@ -1,5 +1,6 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_25 { + #region INCLUDE using System; using System.Collections.Generic; using System.Linq; @@ -16,20 +17,30 @@ public static void Main() IEnumerable even = new int[] { 0, 2, 4, 6, 8 }; Print("Even integers: {0}", even); + #region HIGHLIGHT IEnumerable odd = stuff.OfType(); + #endregion HIGHLIGHT Print("Odd integers: {0}", odd); + #region HIGHLIGHT IEnumerable numbers = even.Union(odd); + #endregion HIGHLIGHT Print("Union of odd and even: {0}", numbers); + #region HIGHLIGHT Print("Union with even: {0}", numbers.Union(even)); Print("Concat with odd: {0}", numbers.Concat(odd)); + #endregion HIGHLIGHT Print("Intersection with even: {0}", + #region HIGHLIGHT numbers.Intersect(even)); Print("Distinct: {0}", numbers.Concat(odd).Distinct()); + #endregion HIGHLIGHT + #region HIGHLIGHT if (!numbers.SequenceEqual( numbers.Concat(odd).Distinct())) + #endregion HIGHLIGHT { throw new Exception("Unexpectedly unequal"); } @@ -39,24 +50,27 @@ public static void Main() @"Collection ""SequenceEquals""" + $" {nameof(numbers)}.Concat(odd).Distinct())"); } + #region HIGHLIGHT Print("Reverse: {0}", numbers.Reverse()); Print("Average: {0}", numbers.Average()); Print("Sum: {0}", numbers.Sum()); Print("Max: {0}", numbers.Max()); Print("Min: {0}", numbers.Min()); - + #endregion HIGHLIGHT } - private static void Print - ( + private static void Print( string format, IEnumerable items) where T : notnull => Console.WriteLine(format, string.Join( - ", ", items.Select(x => x.ToString()))); + ", ", items)); + #region EXCLUDE private static void Print(string format, T item) { Console.WriteLine(format, item); } + #endregion EXCLUDE } + #endregion INCLUDE } diff --git a/src/Chapter15/Listing15.26.ImplicitLocalVariablesWithAnonymousTypes.cs b/src/Chapter15/Listing15.26.ImplicitLocalVariablesWithAnonymousTypes.cs index 99360c4c4..401020714 100644 --- a/src/Chapter15/Listing15.26.ImplicitLocalVariablesWithAnonymousTypes.cs +++ b/src/Chapter15/Listing15.26.ImplicitLocalVariablesWithAnonymousTypes.cs @@ -1,11 +1,13 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_26 { + #region INCLUDE using System; public class Program { public static void Main() { + #region HIGHLIGHT var patent1 = new { @@ -25,6 +27,7 @@ public static void Main() // Renamed to show property naming Year = patent1.YearOfPublication }; + #endregion HIGHLIGHT Console.WriteLine( $"{ patent1.Title } ({ patent1.YearOfPublication })"); @@ -40,4 +43,5 @@ public static void Main() Console.WriteLine(patent3); } } + #endregion INCLUDE } diff --git a/src/Chapter15/Listing15.27.ProjectionToAnAnonymousType.cs b/src/Chapter15/Listing15.27.ProjectionToAnAnonymousType.cs index 249dea4b2..f0156baba 100644 --- a/src/Chapter15/Listing15.27.ProjectionToAnAnonymousType.cs +++ b/src/Chapter15/Listing15.27.ProjectionToAnAnonymousType.cs @@ -4,16 +4,18 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_27 using System.Collections.Generic; using System.IO; using System.Linq; - + #region INCLUDE + #region EXCLUDE public class Program { public static void Main() { string rootDirectory = Directory.GetCurrentDirectory(); string searchPattern = "*"; - + #endregion EXCLUDE IEnumerable fileList = Directory.EnumerateFiles( rootDirectory, searchPattern); + #region HIGHLIGHT var items = fileList.Select( file => { @@ -24,6 +26,8 @@ public static void Main() Size = fileInfo.Length }; }); + #endregion HIGHLIGHT + #region EXCLUDE Print(items); } @@ -36,4 +40,6 @@ private static void Print(IEnumerable items) } } } + #endregion EXCLUDE + #endregion INCLUDE } diff --git a/src/Chapter15/Listing15.28.TypeSafetyAndImmutabilityOfAnonymousTypes.cs b/src/Chapter15/Listing15.28.TypeSafetyAndImmutabilityOfAnonymousTypes.cs index f04aad5dc..3ddb917c9 100644 --- a/src/Chapter15/Listing15.28.TypeSafetyAndImmutabilityOfAnonymousTypes.cs +++ b/src/Chapter15/Listing15.28.TypeSafetyAndImmutabilityOfAnonymousTypes.cs @@ -1,8 +1,9 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_28 { - class Program + #region INCLUDE + public class Program { - static void Main() + public static void Main() { var patent1 = new @@ -34,7 +35,9 @@ static void Main() // ERROR: Property or indexer 'AnonymousType#1.Title' // cannot be assigned to -- it is read-only' - //patent1.Title = "Swiss Cheese"; //won't compile if uncommented + //patent1.Title = "Swiss Cheese"; + //won't compile if uncommented } } + #endregion INCLUDE } diff --git a/src/Chapter15/Listing15.29.InitializingAnonymousTypeArrays.cs b/src/Chapter15/Listing15.29.InitializingAnonymousTypeArrays.cs index 8fbb409e3..09dcb263d 100644 --- a/src/Chapter15/Listing15.29.InitializingAnonymousTypeArrays.cs +++ b/src/Chapter15/Listing15.29.InitializingAnonymousTypeArrays.cs @@ -1,5 +1,6 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_29 { + #region INCLUDE using System; using System.Collections.Generic; @@ -42,4 +43,5 @@ private static void Print(IEnumerable items) } } } + #endregion INCLUDE } From 1a451db45e7f928108d48c1d227dbd6d64f68c58 Mon Sep 17 00:00:00 2001 From: Hanna Michaelis Date: Tue, 5 Jul 2022 14:57:46 -0700 Subject: [PATCH 02/13] ch 14 & 15 removing redundancies --- ...ingthePlusEqualsAndMinusEqualsDelegateOperators.cs | 11 +++++------ .../Listing15.27.ProjectionToAnAnonymousType.cs | 10 ++++------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/Chapter14/Listing14.07.UsingthePlusEqualsAndMinusEqualsDelegateOperators.cs b/src/Chapter14/Listing14.07.UsingthePlusEqualsAndMinusEqualsDelegateOperators.cs index 2f265a120..248610e16 100644 --- a/src/Chapter14/Listing14.07.UsingthePlusEqualsAndMinusEqualsDelegateOperators.cs +++ b/src/Chapter14/Listing14.07.UsingthePlusEqualsAndMinusEqualsDelegateOperators.cs @@ -3,13 +3,13 @@ using System; using Listing14_01; using Listing14_05; - #region INCLUDE - #region EXCLUDE + public class Program { public static void Main() { - #endregion EXCLUDE + #region INCLUDE + //... Thermostat thermostat = new Thermostat(); Heater heater = new Heater(60); Cooler cooler = new Cooler(80); @@ -33,9 +33,8 @@ public static void Main() delegate3 -= delegate1; #endregion HIGHLIGHT delegate3!(30); - #region EXCLUDE + //... + #endregion INCLUDE } } - #endregion EXCLUDE - #endregion INCLUDE } \ No newline at end of file diff --git a/src/Chapter15/Listing15.27.ProjectionToAnAnonymousType.cs b/src/Chapter15/Listing15.27.ProjectionToAnAnonymousType.cs index f0156baba..195e68515 100644 --- a/src/Chapter15/Listing15.27.ProjectionToAnAnonymousType.cs +++ b/src/Chapter15/Listing15.27.ProjectionToAnAnonymousType.cs @@ -4,15 +4,14 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_27 using System.Collections.Generic; using System.IO; using System.Linq; - #region INCLUDE - #region EXCLUDE public class Program { public static void Main() { string rootDirectory = Directory.GetCurrentDirectory(); string searchPattern = "*"; - #endregion EXCLUDE + #region INCLUDE + //... IEnumerable fileList = Directory.EnumerateFiles( rootDirectory, searchPattern); #region HIGHLIGHT @@ -27,7 +26,8 @@ public static void Main() }; }); #endregion HIGHLIGHT - #region EXCLUDE + //... + #endregion INCLUDE Print(items); } @@ -40,6 +40,4 @@ private static void Print(IEnumerable items) } } } - #endregion EXCLUDE - #endregion INCLUDE } From 4b2875ab61de636b471bf2db94a4a013f1224492 Mon Sep 17 00:00:00 2001 From: HannaMichaelis <30376671+HannaMichaelis@users.noreply.github.com> Date: Wed, 6 Jul 2022 11:44:55 -0700 Subject: [PATCH 03/13] Update src/Chapter14/Listing14.14.DeclaringAGenericDelegateType.cs Co-authored-by: Kevin B --- src/Chapter14/Listing14.14.DeclaringAGenericDelegateType.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Chapter14/Listing14.14.DeclaringAGenericDelegateType.cs b/src/Chapter14/Listing14.14.DeclaringAGenericDelegateType.cs index f4ddfaa74..48f9d27f7 100644 --- a/src/Chapter14/Listing14.14.DeclaringAGenericDelegateType.cs +++ b/src/Chapter14/Listing14.14.DeclaringAGenericDelegateType.cs @@ -7,7 +7,7 @@ public class Thermostat #region INCLUDE public delegate void EventHandler( object sender, TEventArgs e) - #endregion INCLUDE where TEventArgs : EventArgs; + #endregion INCLUDE } } \ No newline at end of file From 388af68093c0e3b3b3e7343dd5f6a0eeb6ad9c75 Mon Sep 17 00:00:00 2001 From: Hanna Michaelis Date: Wed, 6 Jul 2022 12:02:54 -0700 Subject: [PATCH 04/13] ch 14 changes after pull request --- ...sting14.08.UsingThePlusAndMinusDelegateOperators.cs | 10 ++++------ ...ing14.09.OnTemperatureChangedThrowingAnException.cs | 6 +++--- .../Listing14.10.HandlingExceptionsFromSubscribers.cs | 4 ++-- ....UsingTheAssignmentOperationRatherThanPlusEquals.cs | 4 ++-- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/Chapter14/Listing14.08.UsingThePlusAndMinusDelegateOperators.cs b/src/Chapter14/Listing14.08.UsingThePlusAndMinusDelegateOperators.cs index c727ffe11..c9377adc4 100644 --- a/src/Chapter14/Listing14.08.UsingThePlusAndMinusDelegateOperators.cs +++ b/src/Chapter14/Listing14.08.UsingThePlusAndMinusDelegateOperators.cs @@ -3,13 +3,12 @@ using System; using Listing14_01; using Listing14_05; - #region INCLUDE - #region EXCLUDE public class Program { public static void Main() { - #endregion EXCLUDE + #region INCLUDE + //... Thermostat thermostat = new Thermostat(); Heater heater = new Heater(60); Cooler cooler = new Cooler(80); @@ -34,9 +33,8 @@ public static void Main() delegate3 = (delegate3 - delegate2)!; #endregion HIGHLIGHT delegate3(60); - #region EXCLUDE + //... + #endregion INCLUDE } } - #endregion EXCLUDE - #endregion INCLUDE } \ No newline at end of file diff --git a/src/Chapter14/Listing14.09.OnTemperatureChangedThrowingAnException.cs b/src/Chapter14/Listing14.09.OnTemperatureChangedThrowingAnException.cs index 5eeb1b62a..40faf6f2d 100644 --- a/src/Chapter14/Listing14.09.OnTemperatureChangedThrowingAnException.cs +++ b/src/Chapter14/Listing14.09.OnTemperatureChangedThrowingAnException.cs @@ -28,12 +28,12 @@ public static void Main() string? temperature = Console.ReadLine(); if (!int.TryParse(temperature, out int currentTemperature)) { - Console.WriteLine - ($"'{temperature}' is not a valid integer."); + Console.WriteLine($"'{temperature}'" + + $" is not a valid integer."); return; } thermostat.CurrentTemperature = currentTemperature; } } - #endregion HIGHLIGHT + #endregion INCLUDE } \ No newline at end of file diff --git a/src/Chapter14/Listing14.10.HandlingExceptionsFromSubscribers.cs b/src/Chapter14/Listing14.10.HandlingExceptionsFromSubscribers.cs index 0a9182bdf..fa6ffc727 100644 --- a/src/Chapter14/Listing14.10.HandlingExceptionsFromSubscribers.cs +++ b/src/Chapter14/Listing14.10.HandlingExceptionsFromSubscribers.cs @@ -17,8 +17,8 @@ public float CurrentTemperature if(value != CurrentTemperature) { _CurrentTemperature = value; - Action? - onTemperatureChange = OnTemperatureChange; + Action? onTemperatureChange + = OnTemperatureChange; if (onTemperatureChange != null) { #region HIGHLIGHT diff --git a/src/Chapter14/Listing14.11.UsingTheAssignmentOperationRatherThanPlusEquals.cs b/src/Chapter14/Listing14.11.UsingTheAssignmentOperationRatherThanPlusEquals.cs index 397722032..47c5d8dff 100644 --- a/src/Chapter14/Listing14.11.UsingTheAssignmentOperationRatherThanPlusEquals.cs +++ b/src/Chapter14/Listing14.11.UsingTheAssignmentOperationRatherThanPlusEquals.cs @@ -27,8 +27,8 @@ public static void Main() string? temperature = Console.ReadLine(); if (!int.TryParse(temperature, out int currentTemperature)) { - Console.WriteLine - ($"'{temperature}' is not a valid integer."); + Console.WriteLine($"'{temperature}' " + + $"is not a valid integer."); return; } thermostat.CurrentTemperature = currentTemperature; From 0d94b221dfb27e70657ab4e7358a69ad49fb2985 Mon Sep 17 00:00:00 2001 From: Hanna Michaelis Date: Wed, 6 Jul 2022 13:33:51 -0700 Subject: [PATCH 05/13] 15.13 change --- src/Chapter15/Listing15.13.ProjectionToATuple.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Chapter15/Listing15.13.ProjectionToATuple.cs b/src/Chapter15/Listing15.13.ProjectionToATuple.cs index 92778cf03..1bde64194 100644 --- a/src/Chapter15/Listing15.13.ProjectionToATuple.cs +++ b/src/Chapter15/Listing15.13.ProjectionToATuple.cs @@ -23,6 +23,7 @@ public static void Main() Size: fileInfo.Length ); }); + #endregion HIGHLIGHT //... #endregion INCLUDE From d4013c62a282ca9e9a2da658c85e54a97a755410 Mon Sep 17 00:00:00 2001 From: Hanna Michaelis Date: Wed, 6 Jul 2022 13:49:54 -0700 Subject: [PATCH 06/13] ch 14 & 15 single lines --- .../Listing14.03.ConnectingThePublisherAndSubscribers.cs | 3 +-- ...isting14.09.OnTemperatureChangedThrowingAnException.cs | 3 +-- ....11.UsingTheAssignmentOperationRatherThanPlusEquals.cs | 3 +-- src/Chapter14/Listing14.19.CustomAddAndRemoveHandlers.cs | 8 ++++---- ...ChildCollectionWithSystem.Linq.Enumerable.GroupJoin.cs | 7 ++----- 5 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/Chapter14/Listing14.03.ConnectingThePublisherAndSubscribers.cs b/src/Chapter14/Listing14.03.ConnectingThePublisherAndSubscribers.cs index 3b17959de..48c45e686 100644 --- a/src/Chapter14/Listing14.03.ConnectingThePublisherAndSubscribers.cs +++ b/src/Chapter14/Listing14.03.ConnectingThePublisherAndSubscribers.cs @@ -23,8 +23,7 @@ public static void Main() string? temperature = Console.ReadLine(); if (!int.TryParse(temperature, out int currentTemperature)) { - Console.WriteLine - ($"'{temperature}' is not a valid integer."); + Console.WriteLine($"'{temperature}' is not a valid integer."); return; } thermostat.CurrentTemperature = currentTemperature; diff --git a/src/Chapter14/Listing14.09.OnTemperatureChangedThrowingAnException.cs b/src/Chapter14/Listing14.09.OnTemperatureChangedThrowingAnException.cs index 40faf6f2d..26d076a6e 100644 --- a/src/Chapter14/Listing14.09.OnTemperatureChangedThrowingAnException.cs +++ b/src/Chapter14/Listing14.09.OnTemperatureChangedThrowingAnException.cs @@ -28,8 +28,7 @@ public static void Main() string? temperature = Console.ReadLine(); if (!int.TryParse(temperature, out int currentTemperature)) { - Console.WriteLine($"'{temperature}'" + - $" is not a valid integer."); + Console.WriteLine($"'{temperature}' is not a valid integer."); return; } thermostat.CurrentTemperature = currentTemperature; diff --git a/src/Chapter14/Listing14.11.UsingTheAssignmentOperationRatherThanPlusEquals.cs b/src/Chapter14/Listing14.11.UsingTheAssignmentOperationRatherThanPlusEquals.cs index 47c5d8dff..8849d3b91 100644 --- a/src/Chapter14/Listing14.11.UsingTheAssignmentOperationRatherThanPlusEquals.cs +++ b/src/Chapter14/Listing14.11.UsingTheAssignmentOperationRatherThanPlusEquals.cs @@ -27,8 +27,7 @@ public static void Main() string? temperature = Console.ReadLine(); if (!int.TryParse(temperature, out int currentTemperature)) { - Console.WriteLine($"'{temperature}' " + - $"is not a valid integer."); + Console.WriteLine($"'{temperature}' is not a valid integer."); return; } thermostat.CurrentTemperature = currentTemperature; diff --git a/src/Chapter14/Listing14.19.CustomAddAndRemoveHandlers.cs b/src/Chapter14/Listing14.19.CustomAddAndRemoveHandlers.cs index 61ca241d0..c5e96db1b 100644 --- a/src/Chapter14/Listing14.19.CustomAddAndRemoveHandlers.cs +++ b/src/Chapter14/Listing14.19.CustomAddAndRemoveHandlers.cs @@ -25,14 +25,14 @@ public event EventHandler OnTemperatureChange add { _OnTemperatureChange = - (EventHandler)System.Delegate.Combine - (value, _OnTemperatureChange); + (EventHandler) + System.Delegate.Combine(value, _OnTemperatureChange); } remove { _OnTemperatureChange = - (EventHandler?)System.Delegate.Remove - (_OnTemperatureChange, value); + (EventHandler?) + System.Delegate.Remove(_OnTemperatureChange, value); } } protected EventHandler? _OnTemperatureChange; diff --git a/src/Chapter15/Listing15.22.CreatingAChildCollectionWithSystem.Linq.Enumerable.GroupJoin.cs b/src/Chapter15/Listing15.22.CreatingAChildCollectionWithSystem.Linq.Enumerable.GroupJoin.cs index b1af44a44..37f03f4e3 100644 --- a/src/Chapter15/Listing15.22.CreatingAChildCollectionWithSystem.Linq.Enumerable.GroupJoin.cs +++ b/src/Chapter15/Listing15.22.CreatingAChildCollectionWithSystem.Linq.Enumerable.GroupJoin.cs @@ -15,9 +15,7 @@ public static void Main() Department[] departments = CorporateData.Departments; Employee[] employees = CorporateData.Employees; - IEnumerable< - (long Id, string Name, IEnumerable Employees)> - items = + IEnumerable<(long Id, string Name, IEnumerable Employees)> items = departments.GroupJoin( employees, department => department.Id, @@ -29,8 +27,7 @@ public static void Main() )); foreach ( - (_, string name, IEnumerable employeeCollection) - in items) + (_, string name, IEnumerable employeeCollection) in items) { Console.WriteLine(name); foreach (Employee employee in employeeCollection) From 848175c42b5c4f6b479322dccc329a06fc8408d6 Mon Sep 17 00:00:00 2001 From: HannaMichaelis <30376671+HannaMichaelis@users.noreply.github.com> Date: Wed, 6 Jul 2022 13:51:22 -0700 Subject: [PATCH 07/13] Update src/Chapter15/Listing15.19.AnInnerJoinUsingSystem.Linq.Enumerable.Join.cs Co-authored-by: Benjamin Michaelis --- ...isting15.19.AnInnerJoinUsingSystem.Linq.Enumerable.Join.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Chapter15/Listing15.19.AnInnerJoinUsingSystem.Linq.Enumerable.Join.cs b/src/Chapter15/Listing15.19.AnInnerJoinUsingSystem.Linq.Enumerable.Join.cs index 57ad4eb29..617316975 100644 --- a/src/Chapter15/Listing15.19.AnInnerJoinUsingSystem.Linq.Enumerable.Join.cs +++ b/src/Chapter15/Listing15.19.AnInnerJoinUsingSystem.Linq.Enumerable.Join.cs @@ -28,9 +28,7 @@ public static void Main() )); - foreach - ((int Id, string Name, string Title, - Department Department) item in items) + foreach ((int Id, string Name, string Title, Department Department) item in items) { Console.WriteLine( $"{item.Name} ({item.Title})"); From 726370c340edc7ba0cb796e570bdd490f29bf01f Mon Sep 17 00:00:00 2001 From: HannaMichaelis <30376671+HannaMichaelis@users.noreply.github.com> Date: Wed, 6 Jul 2022 13:52:02 -0700 Subject: [PATCH 08/13] Update src/Chapter15/Listing15.20.AnotherInnerJoinWithSystem.Linq.Enumerable.Join.cs Co-authored-by: Benjamin Michaelis --- ...ing15.20.AnotherInnerJoinWithSystem.Linq.Enumerable.Join.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Chapter15/Listing15.20.AnotherInnerJoinWithSystem.Linq.Enumerable.Join.cs b/src/Chapter15/Listing15.20.AnotherInnerJoinWithSystem.Linq.Enumerable.Join.cs index 214b0b76f..5bceb28ab 100644 --- a/src/Chapter15/Listing15.20.AnotherInnerJoinWithSystem.Linq.Enumerable.Join.cs +++ b/src/Chapter15/Listing15.20.AnotherInnerJoinWithSystem.Linq.Enumerable.Join.cs @@ -27,8 +27,7 @@ public static void Main() ); - foreach - ((long Id, string Name, Employee Employee) item in items) + foreach ((long Id, string Name, Employee Employee) item in items) { Console.WriteLine(item.Name); Console.WriteLine("\t" + item.Employee); From 2de525b22293084aaff16beb4ee8203cabf12236 Mon Sep 17 00:00:00 2001 From: Benjamin Michaelis Date: Wed, 6 Jul 2022 15:02:25 -0700 Subject: [PATCH 09/13] Fix errors --- .../Listing14.19.CustomAddAndRemoveHandlers.Tests.cs | 3 ++- src/Chapter15/Listing15.13.ProjectionToATuple.cs | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Chapter14.Tests/Listing14.19.CustomAddAndRemoveHandlers.Tests.cs b/src/Chapter14.Tests/Listing14.19.CustomAddAndRemoveHandlers.Tests.cs index ea600963a..72e822768 100644 --- a/src/Chapter14.Tests/Listing14.19.CustomAddAndRemoveHandlers.Tests.cs +++ b/src/Chapter14.Tests/Listing14.19.CustomAddAndRemoveHandlers.Tests.cs @@ -3,6 +3,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_19.Tests { using Listing14_19; + using static AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_19.Thermostat; [TestClass] public class ProgramTests @@ -14,7 +15,7 @@ public void AddRemoveHandlerWorks() float temp = 0; - Thermostat.TemperatureChangeHandler T_OnTemperatureChange = (sender, newTemperature) => + Thermostat.EventHandler T_OnTemperatureChange = (sender, newTemperature) => { temp = newTemperature.NewTemperature; }; diff --git a/src/Chapter15/Listing15.13.ProjectionToATuple.cs b/src/Chapter15/Listing15.13.ProjectionToATuple.cs index 1bde64194..58f6fd7a5 100644 --- a/src/Chapter15/Listing15.13.ProjectionToATuple.cs +++ b/src/Chapter15/Listing15.13.ProjectionToATuple.cs @@ -3,6 +3,8 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_13 using System; using System.Collections.Generic; using System.IO; + using System.Linq; + public class Program { public static void Main() From 0c13b263560be3c6dba2f8cb0798435680b09dce Mon Sep 17 00:00:00 2001 From: Benjamin Michaelis Date: Wed, 6 Jul 2022 23:11:49 +0100 Subject: [PATCH 10/13] Apply suggestions from code review --- ...ting14.01.HeaterAndCoolerEventSubscriberImplementations.cs | 4 ++-- .../Listing14.02.DefiningTheEventPublsherThermostat.cs | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Chapter14/Listing14.01.HeaterAndCoolerEventSubscriberImplementations.cs b/src/Chapter14/Listing14.01.HeaterAndCoolerEventSubscriberImplementations.cs index 2bf66aa44..c0297b914 100644 --- a/src/Chapter14/Listing14.01.HeaterAndCoolerEventSubscriberImplementations.cs +++ b/src/Chapter14/Listing14.01.HeaterAndCoolerEventSubscriberImplementations.cs @@ -33,8 +33,8 @@ public Heater(float temperature) Temperature = temperature; } - // Cooler is activated when ambient temperature - // is higher than this + // Heater is activated when ambient temperature + // is lower than this public float Temperature { get; set; } // Notifies that the temperature changed on this instance diff --git a/src/Chapter14/Listing14.02.DefiningTheEventPublsherThermostat.cs b/src/Chapter14/Listing14.02.DefiningTheEventPublsherThermostat.cs index cad221046..b308d3ed2 100644 --- a/src/Chapter14/Listing14.02.DefiningTheEventPublsherThermostat.cs +++ b/src/Chapter14/Listing14.02.DefiningTheEventPublsherThermostat.cs @@ -9,6 +9,5 @@ public class Thermostat public float CurrentTemperature { get; set; } #endregion INCLUDE - private float _CurrentTemperature; } } \ No newline at end of file From 14f3e208b40253682725578309c4dc373b03e71d Mon Sep 17 00:00:00 2001 From: Benjamin Michaelis Date: Wed, 6 Jul 2022 23:12:49 +0100 Subject: [PATCH 11/13] Update src/Chapter14/Listing14.18.CSharpConceptualEquivalentOfEventCILCode.cs --- .../Listing14.18.CSharpConceptualEquivalentOfEventCILCode.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Chapter14/Listing14.18.CSharpConceptualEquivalentOfEventCILCode.cs b/src/Chapter14/Listing14.18.CSharpConceptualEquivalentOfEventCILCode.cs index 5a90322e3..71d3df830 100644 --- a/src/Chapter14/Listing14.18.CSharpConceptualEquivalentOfEventCILCode.cs +++ b/src/Chapter14/Listing14.18.CSharpConceptualEquivalentOfEventCILCode.cs @@ -35,7 +35,7 @@ public void remove_OnTemperatureChange( System.Delegate.Remove(_OnTemperatureChange, handler); } - #if ConceptulEquivalendCode + #if ConceptualEquivalentCode public event EventHandler OnTemperatureChange { //Would cause a compiler error From e0d3421ed81da17df68afce2880ea6090b29e14f Mon Sep 17 00:00:00 2001 From: Benjamin Michaelis Date: Wed, 6 Jul 2022 23:13:15 +0100 Subject: [PATCH 12/13] Update src/Chapter14/Listing14.18.CSharpConceptualEquivalentOfEventCILCode.cs --- .../Listing14.18.CSharpConceptualEquivalentOfEventCILCode.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Chapter14/Listing14.18.CSharpConceptualEquivalentOfEventCILCode.cs b/src/Chapter14/Listing14.18.CSharpConceptualEquivalentOfEventCILCode.cs index 71d3df830..cf1431034 100644 --- a/src/Chapter14/Listing14.18.CSharpConceptualEquivalentOfEventCILCode.cs +++ b/src/Chapter14/Listing14.18.CSharpConceptualEquivalentOfEventCILCode.cs @@ -49,7 +49,7 @@ public event EventHandler OnTemperatureChange remove_OnTemperatureChange(value); } } - #endif // ConceptulEquivalendCode + #endif // ConceptualEquivalentCode #endregion INCLUDE public class TemperatureArgs : System.EventArgs From f155412a1053b9e503d807509ddb088d661f46b4 Mon Sep 17 00:00:00 2001 From: Benjamin Michaelis Date: Wed, 6 Jul 2022 15:15:05 -0700 Subject: [PATCH 13/13] Delete snippet file --- pp_region.snippet | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 pp_region.snippet diff --git a/pp_region.snippet b/pp_region.snippet deleted file mode 100644 index 44b8f27bc..000000000 --- a/pp_region.snippet +++ /dev/null @@ -1,28 +0,0 @@ - - - -
- #region - #region - Essential C# Region - Microsoft Corporation - - Expansion - SurroundsWith - -
- - - - name - Region name - MyRegion - - - - - -
-
\ No newline at end of file