From 1e5eabcb028966eb94daf677a571a6f3515e9f85 Mon Sep 17 00:00:00 2001 From: Benjamin Michaelis Date: Wed, 8 Nov 2023 04:33:36 +0100 Subject: [PATCH] feat: Add rule for modifier order and fix violations (#580) --- .editorconfig | 2 ++ EssentialCSharp.sln | 1 + src/Chapter03/Table03.02.ArrayHighlights.cs | 8 ++++---- src/Chapter03/Table03.03.a.CommonArrayCodingErrors.cs | 2 +- src/Chapter03/Table03.03.b.CommonArrayCodingErrors.cs | 2 +- src/Chapter03/Table03.03.c.CommonArrayCodingErrors.cs | 2 +- src/Chapter03/Table03.03.d.CommonArrayCodingErrors.cs | 2 +- src/Chapter03/Table03.03.e.CommonArrayCodingErrors.cs | 2 +- src/Chapter03/Table03.03.f.CommonArrayCodingErrors.cs | 2 +- src/Chapter03/Table03.03.g.CommonArrayCodingErrors.cs | 2 +- src/Chapter03/Table03.03.h.CommonArrayCodingErrors.cs | 2 +- src/Chapter03/Table03.03.i.CommonArrayCodingErrors.cs | 2 +- src/Chapter03/Table03.03.j.CommonArrayCodingErrors.cs | 2 +- src/Chapter04/TicTacToe.cs | 2 +- .../Listing05.06.ReturningMultipleValuesViaTuples.cs | 2 +- ...06.41.UsingNotNullWhenAndNotNullIfNotNullAttributes.cs | 4 ++-- ...ting06.42.PotentialNullReturnWithMaybeNullAttribute.cs | 4 ++-- ...ProtectedMembersAreAccessibleOnlyFromDerivedClasses.cs | 2 +- src/Chapter07/Listing07.12.OverrideVersusNewModifier.cs | 2 +- src/Chapter07/Listing07.13.SealingMembers.cs | 2 +- .../Listing07.34.DataConversionUsingTheAsOperator.cs | 2 +- src/Chapter08.Tests/UndersandingAccessModifiers.Tests.cs | 6 +++--- .../Listing08.02.ImplementingAndUsingInterfaces.cs | 2 +- src/Chapter08/Listing08.03.ImplementingAnInterface.cs | 2 +- ...08.04.CallingExplicitInterfaceMemberImplementations.cs | 2 +- .../Listing08.05.ExplicitInterfaceImplementation.cs | 2 +- .../Listing08.12.DefaultImplementedInterfaceMembers.cs | 4 ++-- .../Listing08.14.ForcingTheDesirableRunEncapsulation.cs | 2 +- .../Table08.01.DefaultImplementedInterfaceMembers.cs | 2 +- ...ing10.18.RegisteringAFinalizerWithProcessExit.Tests.cs | 2 +- src/Chapter10/Listing10.14.WeakReferences.cs | 6 +++--- ...g11.03.UsingExceptionDispatchInfoToRethrowException.cs | 2 +- ...Listing12.06.ImplementingUndoWithAGenericStackClass.cs | 4 ++-- ...4.DeclaringAGenericWithAMulticastDelegateConstraint.cs | 4 ++-- src/Chapter12/Listing12.49.StackIntDefinition.cs | 2 +- .../Table13.01.b.LambdaExpressionNotesAndExamples.cs | 2 +- .../Table13.01.c.LambdaExpressionNotesAndExamples.cs | 2 +- src/Chapter20.Tests/Listing20.01.Tests.cs | 2 +- src/Chapter20/Listing20.10.AsynchronousAsALambda.cs | 2 +- .../Listing22.01.UnsychronizedState.Tests.cs | 2 +- src/Chapter22/Listing22.03.SynchronizingWithMonitor.cs | 2 +- .../Listing22.04.SynchronizingWithLockKeyword.cs | 2 +- src/Chapter22/Listing22.05.AsyncMain.cs | 2 +- src/Shared/Cryptographer.cs | 4 ++-- src/Shared/Tests/PowerShellTestUtilities.cs | 4 ++-- 45 files changed, 60 insertions(+), 57 deletions(-) diff --git a/.editorconfig b/.editorconfig index 3b3dd0805..216ca6f2c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -366,3 +366,5 @@ spelling_exclusion_path = .\exclusion.dic spelling_checkable_types = strings,identifiers,comments spelling_error_severity = error +# Custom Rules +dotnet_diagnostic.IDE0036.severity = warning \ No newline at end of file diff --git a/EssentialCSharp.sln b/EssentialCSharp.sln index 370f136c7..d81bb00bb 100644 --- a/EssentialCSharp.sln +++ b/EssentialCSharp.sln @@ -4,6 +4,7 @@ VisualStudioVersion = 17.2.32616.157 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F97BC459-B5B9-4326-9E0D-D085FD4DEF96}" ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig .gitignore = .gitignore .runsettings = .runsettings after.EssentialCSharp.sln.targets = after.EssentialCSharp.sln.targets diff --git a/src/Chapter03/Table03.02.ArrayHighlights.cs b/src/Chapter03/Table03.02.ArrayHighlights.cs index ed570eed8..fbf1ae9f2 100644 --- a/src/Chapter03/Table03.02.ArrayHighlights.cs +++ b/src/Chapter03/Table03.02.ArrayHighlights.cs @@ -6,14 +6,14 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_02; public class ArrayHighlights { // 1. - static public void Declaration() + public static void Declaration() { string[] languages; // one-dimensional int[,] cells; // two-dimensional } // 2. - static public void Assignment() + public static void Assignment() { string[] languages = { "C#", "COBOL", "Java", @@ -34,7 +34,7 @@ static public void Assignment() } // 3. - static public void ForwardAndReverseAccessingAnArray() + public static void ForwardAndReverseAccessingAnArray() { string[] languages = new []{ "C#", "COBOL", "Java", @@ -51,7 +51,7 @@ static public void ForwardAndReverseAccessingAnArray() } // 4. - static public void Ranges() + public static void Ranges() { string[] languages = new []{ "C#", "COBOL", "Java", diff --git a/src/Chapter03/Table03.03.a.CommonArrayCodingErrors.cs b/src/Chapter03/Table03.03.a.CommonArrayCodingErrors.cs index ade797ebc..1e8aa3b4e 100644 --- a/src/Chapter03/Table03.03.a.CommonArrayCodingErrors.cs +++ b/src/Chapter03/Table03.03.a.CommonArrayCodingErrors.cs @@ -6,7 +6,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03; public partial class CommonArrayCodingErrors { // 1. - static public void SquareBracketsOnVariableRatherThanType() + public static void SquareBracketsOnVariableRatherThanType() { #if COMPILEERROR int numbers[]; diff --git a/src/Chapter03/Table03.03.b.CommonArrayCodingErrors.cs b/src/Chapter03/Table03.03.b.CommonArrayCodingErrors.cs index 53e060e6b..d948dc2dc 100644 --- a/src/Chapter03/Table03.03.b.CommonArrayCodingErrors.cs +++ b/src/Chapter03/Table03.03.b.CommonArrayCodingErrors.cs @@ -6,7 +6,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03; public partial class CommonArrayCodingErrors { // 2. - static public void NewKeywordWithDataTypeRequired() + public static void NewKeywordWithDataTypeRequired() { #if COMPILEERROR int[] numbers; diff --git a/src/Chapter03/Table03.03.c.CommonArrayCodingErrors.cs b/src/Chapter03/Table03.03.c.CommonArrayCodingErrors.cs index 4cac251a9..99bd84676 100644 --- a/src/Chapter03/Table03.03.c.CommonArrayCodingErrors.cs +++ b/src/Chapter03/Table03.03.c.CommonArrayCodingErrors.cs @@ -6,7 +6,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03; public partial class CommonArrayCodingErrors { // 3. - static public void ArraySizeCannotBeSpecifiedInDataType() + public static void ArraySizeCannotBeSpecifiedInDataType() { #if COMPILEERROR int[3] numbers = diff --git a/src/Chapter03/Table03.03.d.CommonArrayCodingErrors.cs b/src/Chapter03/Table03.03.d.CommonArrayCodingErrors.cs index 18af207c5..732d8c839 100644 --- a/src/Chapter03/Table03.03.d.CommonArrayCodingErrors.cs +++ b/src/Chapter03/Table03.03.d.CommonArrayCodingErrors.cs @@ -6,7 +6,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03; public partial class CommonArrayCodingErrors { // 4. - static public void ArraySizeOrInitializerIsRequired() + public static void ArraySizeOrInitializerIsRequired() { #if COMPILEERROR int[] numbers = diff --git a/src/Chapter03/Table03.03.e.CommonArrayCodingErrors.cs b/src/Chapter03/Table03.03.e.CommonArrayCodingErrors.cs index a0231a6e3..c2c3ec709 100644 --- a/src/Chapter03/Table03.03.e.CommonArrayCodingErrors.cs +++ b/src/Chapter03/Table03.03.e.CommonArrayCodingErrors.cs @@ -6,7 +6,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03; public partial class CommonArrayCodingErrors { // 5. - static public void ArraySizeWithEmptyInitializer() + public static void ArraySizeWithEmptyInitializer() { #if COMPILEERROR int[] numbers = diff --git a/src/Chapter03/Table03.03.f.CommonArrayCodingErrors.cs b/src/Chapter03/Table03.03.f.CommonArrayCodingErrors.cs index 18caf7935..56790e014 100644 --- a/src/Chapter03/Table03.03.f.CommonArrayCodingErrors.cs +++ b/src/Chapter03/Table03.03.f.CommonArrayCodingErrors.cs @@ -6,7 +6,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03; public partial class CommonArrayCodingErrors { // 6. - static public void IndexingOffTheEndOfArray() + public static void IndexingOffTheEndOfArray() { int[] numbers = new int[3]; diff --git a/src/Chapter03/Table03.03.g.CommonArrayCodingErrors.cs b/src/Chapter03/Table03.03.g.CommonArrayCodingErrors.cs index 6d7bbd052..fa6688aff 100644 --- a/src/Chapter03/Table03.03.g.CommonArrayCodingErrors.cs +++ b/src/Chapter03/Table03.03.g.CommonArrayCodingErrors.cs @@ -6,7 +6,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03; public partial class CommonArrayCodingErrors { // 7. - static public void Hat0IsOnePastTheEndOfTheArray1() + public static void Hat0IsOnePastTheEndOfTheArray1() { int[] numbers = new int[3]; diff --git a/src/Chapter03/Table03.03.h.CommonArrayCodingErrors.cs b/src/Chapter03/Table03.03.h.CommonArrayCodingErrors.cs index d3255c390..102fd8660 100644 --- a/src/Chapter03/Table03.03.h.CommonArrayCodingErrors.cs +++ b/src/Chapter03/Table03.03.h.CommonArrayCodingErrors.cs @@ -6,7 +6,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03; public partial class CommonArrayCodingErrors { // 8. - static public void LastItemIsLengthMinus1() + public static void LastItemIsLengthMinus1() { int[] numbers = new int[3]; diff --git a/src/Chapter03/Table03.03.i.CommonArrayCodingErrors.cs b/src/Chapter03/Table03.03.i.CommonArrayCodingErrors.cs index 12cd0ee32..76f97db6c 100644 --- a/src/Chapter03/Table03.03.i.CommonArrayCodingErrors.cs +++ b/src/Chapter03/Table03.03.i.CommonArrayCodingErrors.cs @@ -6,7 +6,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03; public partial class CommonArrayCodingErrors { // 9. - static public void MultiDimensionalArrayWithInconsistentSize() + public static void MultiDimensionalArrayWithInconsistentSize() { #if COMPILEERROR int[,] numbers = diff --git a/src/Chapter03/Table03.03.j.CommonArrayCodingErrors.cs b/src/Chapter03/Table03.03.j.CommonArrayCodingErrors.cs index 84c7d3b83..520d2f325 100644 --- a/src/Chapter03/Table03.03.j.CommonArrayCodingErrors.cs +++ b/src/Chapter03/Table03.03.j.CommonArrayCodingErrors.cs @@ -6,7 +6,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03; public partial class CommonArrayCodingErrors { // 10. - static public void MembersInJaggedArraysMustBeInstantiated() + public static void MembersInJaggedArraysMustBeInstantiated() { #if COMPILEERROR int[][] numbers = diff --git a/src/Chapter04/TicTacToe.cs b/src/Chapter04/TicTacToe.cs index e645cf300..60baf79ce 100644 --- a/src/Chapter04/TicTacToe.cs +++ b/src/Chapter04/TicTacToe.cs @@ -11,7 +11,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.TicTacToe; // play tic-tac-toe. public class TicTacToeGame // Declares the TicTacToeGame class. { - static public void Main() // Declares the entry point to the program. + public static void Main() // Declares the entry point to the program. { // Stores locations each player has moved. int[] playerPositions = { 0, 0 }; diff --git a/src/Chapter05/Listing05.06.ReturningMultipleValuesViaTuples.cs b/src/Chapter05/Listing05.06.ReturningMultipleValuesViaTuples.cs index 1422d5409..090d2df1f 100644 --- a/src/Chapter05/Listing05.06.ReturningMultipleValuesViaTuples.cs +++ b/src/Chapter05/Listing05.06.ReturningMultipleValuesViaTuples.cs @@ -17,7 +17,7 @@ static string GetUserInput(string prompt) lastName = GetUserInput("Enter your last name: "); return (firstName, lastName); } - static public void Main() + public static void Main() { #region HIGHLIGHT (string First, string Last) name = GetName(); diff --git a/src/Chapter06/Listing06.41.UsingNotNullWhenAndNotNullIfNotNullAttributes.cs b/src/Chapter06/Listing06.41.UsingNotNullWhenAndNotNullIfNotNullAttributes.cs index 74921691a..a13bb11ab 100644 --- a/src/Chapter06/Listing06.41.UsingNotNullWhenAndNotNullIfNotNullAttributes.cs +++ b/src/Chapter06/Listing06.41.UsingNotNullWhenAndNotNullIfNotNullAttributes.cs @@ -6,7 +6,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_41; public class NullabilityAttributesExamined { #endregion EXCLUDE - static public bool TryGetDigitAsText( + public static bool TryGetDigitAsText( char number, [NotNullWhen(true)]out string? text) => (text = number switch { @@ -25,7 +25,7 @@ static public bool TryGetDigitAsText( #else // EXCLUDE [return: NotNullIfNotNull("text")] // EXCLUDE #endif // EXCLUDE - static public string? TryGetDigitsAsText(string? text) + public static string? TryGetDigitsAsText(string? text) { if (text == null) return null; diff --git a/src/Chapter06/Listing06.42.PotentialNullReturnWithMaybeNullAttribute.cs b/src/Chapter06/Listing06.42.PotentialNullReturnWithMaybeNullAttribute.cs index c3b118105..6ce889422 100644 --- a/src/Chapter06/Listing06.42.PotentialNullReturnWithMaybeNullAttribute.cs +++ b/src/Chapter06/Listing06.42.PotentialNullReturnWithMaybeNullAttribute.cs @@ -8,12 +8,12 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_42; public class NullabilityAttributesExamined { - static public string? Method() => + public static string? Method() => GetObject(Array.Empty(), (item) => true); #region INCLUDE // ... [return: MaybeNull] - static public T GetObject( + public static T GetObject( IEnumerable sequence, Func match) => // ... diff --git a/src/Chapter07/Listing07.07.ProtectedMembersAreAccessibleOnlyFromDerivedClasses.cs b/src/Chapter07/Listing07.07.ProtectedMembersAreAccessibleOnlyFromDerivedClasses.cs index 7f4ef0f98..6c5afb52a 100644 --- a/src/Chapter07/Listing07.07.ProtectedMembersAreAccessibleOnlyFromDerivedClasses.cs +++ b/src/Chapter07/Listing07.07.ProtectedMembersAreAccessibleOnlyFromDerivedClasses.cs @@ -28,7 +28,7 @@ public void Save() // ... stream.Dispose(); } - static public Contact Copy(Contact contact) + public static Contact Copy(Contact contact) #region HIGHLIGHT => new(contact.ObjectKey); #endregion HIGHLIGHT diff --git a/src/Chapter07/Listing07.12.OverrideVersusNewModifier.cs b/src/Chapter07/Listing07.12.OverrideVersusNewModifier.cs index def657214..908475b56 100644 --- a/src/Chapter07/Listing07.12.OverrideVersusNewModifier.cs +++ b/src/Chapter07/Listing07.12.OverrideVersusNewModifier.cs @@ -33,7 +33,7 @@ public override void DisplayName() public class SuperSubDerivedClass : SubDerivedClass { - public new static void DisplayName() + public static new void DisplayName() { Console.WriteLine("SuperSubDerivedClass"); } diff --git a/src/Chapter07/Listing07.13.SealingMembers.cs b/src/Chapter07/Listing07.13.SealingMembers.cs index f7504bc05..3867883d5 100644 --- a/src/Chapter07/Listing07.13.SealingMembers.cs +++ b/src/Chapter07/Listing07.13.SealingMembers.cs @@ -10,7 +10,7 @@ public virtual void Method() class B : A { - public override sealed void Method() + public sealed override void Method() { } } diff --git a/src/Chapter07/Listing07.34.DataConversionUsingTheAsOperator.cs b/src/Chapter07/Listing07.34.DataConversionUsingTheAsOperator.cs index 818b08ad8..92e96bbeb 100644 --- a/src/Chapter07/Listing07.34.DataConversionUsingTheAsOperator.cs +++ b/src/Chapter07/Listing07.34.DataConversionUsingTheAsOperator.cs @@ -12,7 +12,7 @@ public class Contact : PdaItem // ... public Contact(string name) => Name = name; - static public Contact Load(PdaItem pdaItem) + public static Contact Load(PdaItem pdaItem) { #pragma warning disable IDE0019 // Use pattern matching Contact? contact = pdaItem as Contact; diff --git a/src/Chapter08.Tests/UndersandingAccessModifiers.Tests.cs b/src/Chapter08.Tests/UndersandingAccessModifiers.Tests.cs index 03257b3e3..7626f5901 100644 --- a/src/Chapter08.Tests/UndersandingAccessModifiers.Tests.cs +++ b/src/Chapter08.Tests/UndersandingAccessModifiers.Tests.cs @@ -58,15 +58,15 @@ public string CallConcreteInterfaceMethod3() => // Same as casting to ISampleInterface ((ISampleInterface)this).PublicConcreteInterfaceMethod(); - virtual public string PublicConcreteInterfaceMethod() => Thing.GetStackTrace(); + public virtual string PublicConcreteInterfaceMethod() => Thing.GetStackTrace(); } public class SubClass : Information { - public new static string PublicConcreteInterfaceMethod() => Thing.GetStackTrace(); + public static new string PublicConcreteInterfaceMethod() => Thing.GetStackTrace(); } #pragma warning restore IDE0051 // Remove unused private members -static public class Thing +public static class Thing { [MethodImpl(MethodImplOptions.NoInlining)] public static string GetStackTrace() diff --git a/src/Chapter08/Listing08.02.ImplementingAndUsingInterfaces.cs b/src/Chapter08/Listing08.02.ImplementingAndUsingInterfaces.cs index 65c583de1..27ea8aef6 100644 --- a/src/Chapter08/Listing08.02.ImplementingAndUsingInterfaces.cs +++ b/src/Chapter08/Listing08.02.ImplementingAndUsingInterfaces.cs @@ -39,7 +39,7 @@ public Contact(string firstName, string lastName, public string LastName { get; } public string Address { get; } public string Phone { get; } - static public string GetName(string firstName, string lastName) + public static string GetName(string firstName, string lastName) => $"{ firstName } { lastName }"; #region HIGHLIGHT diff --git a/src/Chapter08/Listing08.03.ImplementingAnInterface.cs b/src/Chapter08/Listing08.03.ImplementingAnInterface.cs index 382601f6a..a923460c6 100644 --- a/src/Chapter08/Listing08.03.ImplementingAnInterface.cs +++ b/src/Chapter08/Listing08.03.ImplementingAnInterface.cs @@ -104,7 +104,7 @@ protected string FirstName } protected string? Phone { get; set; } protected string? Address { get; set; } - static public string GetName(string firstName, string lastName) + public static string GetName(string firstName, string lastName) => $"{ firstName } { lastName }"; #endregion EXCLUDE } diff --git a/src/Chapter08/Listing08.04.CallingExplicitInterfaceMemberImplementations.cs b/src/Chapter08/Listing08.04.CallingExplicitInterfaceMemberImplementations.cs index f20148b73..273bd1c0f 100644 --- a/src/Chapter08/Listing08.04.CallingExplicitInterfaceMemberImplementations.cs +++ b/src/Chapter08/Listing08.04.CallingExplicitInterfaceMemberImplementations.cs @@ -71,6 +71,6 @@ protected string FirstName } protected string? Phone { get; set; } protected string? Address { get; set; } - static public string GetName(string firstName, string lastName) + public static string GetName(string firstName, string lastName) => $"{ firstName } { lastName }"; } \ No newline at end of file diff --git a/src/Chapter08/Listing08.05.ExplicitInterfaceImplementation.cs b/src/Chapter08/Listing08.05.ExplicitInterfaceImplementation.cs index 5dc122021..01eb64223 100644 --- a/src/Chapter08/Listing08.05.ExplicitInterfaceImplementation.cs +++ b/src/Chapter08/Listing08.05.ExplicitInterfaceImplementation.cs @@ -99,7 +99,7 @@ protected string FirstName } protected string? Phone { get; set; } protected string? Address { get; set; } - static public string GetName(string firstName, string lastName) + public static string GetName(string firstName, string lastName) => $"{ firstName } { lastName }"; #endregion EXCLUDE } diff --git a/src/Chapter08/Listing08.12.DefaultImplementedInterfaceMembers.cs b/src/Chapter08/Listing08.12.DefaultImplementedInterfaceMembers.cs index ddf55fa69..210e8d220 100644 --- a/src/Chapter08/Listing08.12.DefaultImplementedInterfaceMembers.cs +++ b/src/Chapter08/Listing08.12.DefaultImplementedInterfaceMembers.cs @@ -78,7 +78,7 @@ ConsoleColor[] CellColors } } #region HIGHLIGHT - static public ConsoleColor DefaultColumnColor { get; set; } + public static ConsoleColor DefaultColumnColor { get; set; } #endregion HIGHLIGHT } @@ -144,7 +144,7 @@ public static string[] Headers } } - static public string GetName(string firstName, string lastName) + public static string GetName(string firstName, string lastName) => $"{ firstName } { lastName }"; #endregion EXCLUDE } diff --git a/src/Chapter08/Listing08.14.ForcingTheDesirableRunEncapsulation.cs b/src/Chapter08/Listing08.14.ForcingTheDesirableRunEncapsulation.cs index cfafc5a67..cc4c94e8d 100644 --- a/src/Chapter08/Listing08.14.ForcingTheDesirableRunEncapsulation.cs +++ b/src/Chapter08/Listing08.14.ForcingTheDesirableRunEncapsulation.cs @@ -84,7 +84,7 @@ public static void Run() public class Program { - static public void Main() + public static void Main() { ExecuteProcessActivity activity = new("dotnet"); diff --git a/src/Chapter08/Table08.01.DefaultImplementedInterfaceMembers.cs b/src/Chapter08/Table08.01.DefaultImplementedInterfaceMembers.cs index 24dbb7725..44d8b1a1d 100644 --- a/src/Chapter08/Table08.01.DefaultImplementedInterfaceMembers.cs +++ b/src/Chapter08/Table08.01.DefaultImplementedInterfaceMembers.cs @@ -57,7 +57,7 @@ public Employee(string firstName, string lastName) } public class Program { - static public void Main() + public static void Main() { Person inigo = new("Inigo", "Montoya"); Console.WriteLine( diff --git a/src/Chapter10.Tests/Listing10.18.RegisteringAFinalizerWithProcessExit.Tests.cs b/src/Chapter10.Tests/Listing10.18.RegisteringAFinalizerWithProcessExit.Tests.cs index 6216340c8..7bfed7c78 100644 --- a/src/Chapter10.Tests/Listing10.18.RegisteringAFinalizerWithProcessExit.Tests.cs +++ b/src/Chapter10.Tests/Listing10.18.RegisteringAFinalizerWithProcessExit.Tests.cs @@ -20,7 +20,7 @@ public partial class DisposeTests private const string ProjectName = "ProcessExitTestProgram.testing"; - private readonly static object RunPowerShellScriptSyncLock = new(); + private static readonly object RunPowerShellScriptSyncLock = new(); [ClassInitialize] public static void ClassInitialize(TestContext testContext) { diff --git a/src/Chapter10/Listing10.14.WeakReferences.cs b/src/Chapter10/Listing10.14.WeakReferences.cs index 100fe23e8..51e152b0e 100644 --- a/src/Chapter10/Listing10.14.WeakReferences.cs +++ b/src/Chapter10/Listing10.14.WeakReferences.cs @@ -36,7 +36,7 @@ public T Target #region INCLUDE public static class ByteArrayDataSource { - static private byte[] LoadData() + private static byte[] LoadData() { // Imagine a much lager number byte[] data = new byte[1000]; @@ -45,9 +45,9 @@ static private byte[] LoadData() return data; } - static private WeakReference? Data { get; set; } + private static WeakReference? Data { get; set; } - static public byte[] GetData() + public static byte[] GetData() { byte[]? target; if (Data is null) diff --git a/src/Chapter11/Listing11.03.UsingExceptionDispatchInfoToRethrowException.cs b/src/Chapter11/Listing11.03.UsingExceptionDispatchInfoToRethrowException.cs index e0978a6fc..ed0637733 100644 --- a/src/Chapter11/Listing11.03.UsingExceptionDispatchInfoToRethrowException.cs +++ b/src/Chapter11/Listing11.03.UsingExceptionDispatchInfoToRethrowException.cs @@ -72,7 +72,7 @@ private static Task WriteWebRequestSizeAsync( return task; } - static public string FormatBytes(long bytes) + public static string FormatBytes(long bytes) { string[] magnitudes = new string[] { "GB", "MB", "KB", "Bytes" }; diff --git a/src/Chapter12/Listing12.06.ImplementingUndoWithAGenericStackClass.cs b/src/Chapter12/Listing12.06.ImplementingUndoWithAGenericStackClass.cs index 4b1a49a39..0f86d06c7 100644 --- a/src/Chapter12/Listing12.06.ImplementingUndoWithAGenericStackClass.cs +++ b/src/Chapter12/Listing12.06.ImplementingUndoWithAGenericStackClass.cs @@ -141,8 +141,8 @@ private static void FillCell(Cell cell, ConsoleColor color) #endregion INCLUDE public struct Cell { - readonly public int X; - readonly public int Y; + public readonly int X; + public readonly int Y; public Cell(int x, int y) { diff --git a/src/Chapter12/Listing12.24.DeclaringAGenericWithAMulticastDelegateConstraint.cs b/src/Chapter12/Listing12.24.DeclaringAGenericWithAMulticastDelegateConstraint.cs index 460e57dfb..d139375f6 100644 --- a/src/Chapter12/Listing12.24.DeclaringAGenericWithAMulticastDelegateConstraint.cs +++ b/src/Chapter12/Listing12.24.DeclaringAGenericWithAMulticastDelegateConstraint.cs @@ -3,7 +3,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_31; public class Publisher { #region INCLUDE - static public object? InvokeAll( + public static object? InvokeAll( object?[]? args, params TDelegate[] delegates) // Constraint of type Action/Func not allowed where TDelegate : System.MulticastDelegate @@ -21,7 +21,7 @@ public class Publisher } #endregion INCLUDE - static public void InvokeAll(params Action?[] actions) + public static void InvokeAll(params Action?[] actions) { Action? result = (Action?)Delegate.Combine(actions); result?.Invoke(); diff --git a/src/Chapter12/Listing12.49.StackIntDefinition.cs b/src/Chapter12/Listing12.49.StackIntDefinition.cs index f58e98715..e274be4a0 100644 --- a/src/Chapter12/Listing12.49.StackIntDefinition.cs +++ b/src/Chapter12/Listing12.49.StackIntDefinition.cs @@ -6,7 +6,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_49; public class Program { - static private void Main() + private static void Main() { #region INCLUDE Stack stack; diff --git a/src/Chapter13/Table13.01.b.LambdaExpressionNotesAndExamples.cs b/src/Chapter13/Table13.01.b.LambdaExpressionNotesAndExamples.cs index c7d5898b0..533d39c0d 100644 --- a/src/Chapter13/Table13.01.b.LambdaExpressionNotesAndExamples.cs +++ b/src/Chapter13/Table13.01.b.LambdaExpressionNotesAndExamples.cs @@ -6,7 +6,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter13.Table13_01; public partial class LambdaExpressionNotesAndExamples { // 2. - static public void TypeInferenceOfExpression() + public static void TypeInferenceOfExpression() { #if NET6_0_OR_GREATER //You can assign lambda diff --git a/src/Chapter13/Table13.01.c.LambdaExpressionNotesAndExamples.cs b/src/Chapter13/Table13.01.c.LambdaExpressionNotesAndExamples.cs index e1b64456f..fbe1d42a1 100644 --- a/src/Chapter13/Table13.01.c.LambdaExpressionNotesAndExamples.cs +++ b/src/Chapter13/Table13.01.c.LambdaExpressionNotesAndExamples.cs @@ -6,7 +6,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter13.Table13_01; public partial class LambdaExpressionNotesAndExamples { // 3. - static public void ExpressionsCanHaveReturnTypes() + public static void ExpressionsCanHaveReturnTypes() { #if NET6_0_OR_GREATER Action action = void () => { }; diff --git a/src/Chapter20.Tests/Listing20.01.Tests.cs b/src/Chapter20.Tests/Listing20.01.Tests.cs index d75537488..855c14ab7 100644 --- a/src/Chapter20.Tests/Listing20.01.Tests.cs +++ b/src/Chapter20.Tests/Listing20.01.Tests.cs @@ -6,7 +6,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter20.Listing20_01.Tests; public class ProgramTests : BaseProgramTests { [ClassInitialize] - static public void ClassInitialize(TestContext _) + public static void ClassInitialize(TestContext _) { Program.HttpClient = GetMockedHttpClient(); ProgramWrapper = new ProgramWrapper( diff --git a/src/Chapter20/Listing20.10.AsynchronousAsALambda.cs b/src/Chapter20/Listing20.10.AsynchronousAsALambda.cs index bf68d08ed..a51c2e567 100644 --- a/src/Chapter20/Listing20.10.AsynchronousAsALambda.cs +++ b/src/Chapter20/Listing20.10.AsynchronousAsALambda.cs @@ -60,7 +60,7 @@ public static void Main(string[] args) } } #region EXCLUDE - static public string FormatBytes(long bytes) + public static string FormatBytes(long bytes) { string[] magnitudes = new [] { "GB", "MB", "KB", "Bytes" }; diff --git a/src/Chapter22.Tests/Listing22.01.UnsychronizedState.Tests.cs b/src/Chapter22.Tests/Listing22.01.UnsychronizedState.Tests.cs index 2ad9f6cb8..5c3f40553 100644 --- a/src/Chapter22.Tests/Listing22.01.UnsychronizedState.Tests.cs +++ b/src/Chapter22.Tests/Listing22.01.UnsychronizedState.Tests.cs @@ -35,7 +35,7 @@ public static bool IsIncrementDecrementNotAtomic( return unsynchronized; } - static public void VerifyOutputIncrementAndDecrement(Func main) + public static void VerifyOutputIncrementAndDecrement(Func main) { int? result = null; string expected = $"Increment and decrementing \\d+ times...{Environment.NewLine}Count = (?\\d*)"; diff --git a/src/Chapter22/Listing22.03.SynchronizingWithMonitor.cs b/src/Chapter22/Listing22.03.SynchronizingWithMonitor.cs index c182a4948..064816b6c 100644 --- a/src/Chapter22/Listing22.03.SynchronizingWithMonitor.cs +++ b/src/Chapter22/Listing22.03.SynchronizingWithMonitor.cs @@ -8,7 +8,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter22.Listing22_03; public class Program { #region HIGHLIGHT - readonly static object _Sync = new(); + static readonly object _Sync = new(); #endregion HIGHLIGHT static int _Total = int.MaxValue; static int _Count = 0; diff --git a/src/Chapter22/Listing22.04.SynchronizingWithLockKeyword.cs b/src/Chapter22/Listing22.04.SynchronizingWithLockKeyword.cs index 3603e9183..d41eb021a 100644 --- a/src/Chapter22/Listing22.04.SynchronizingWithLockKeyword.cs +++ b/src/Chapter22/Listing22.04.SynchronizingWithLockKeyword.cs @@ -7,7 +7,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter22.Listing22_04; public class Program { #region HIGHLIGHT - readonly static object _Sync = new(); + static readonly object _Sync = new(); #endregion HIGHLIGHT static int _Total = int.MaxValue; static int _Count = 0; diff --git a/src/Chapter22/Listing22.05.AsyncMain.cs b/src/Chapter22/Listing22.05.AsyncMain.cs index 9749e3c81..980d0ca4b 100644 --- a/src/Chapter22/Listing22.05.AsyncMain.cs +++ b/src/Chapter22/Listing22.05.AsyncMain.cs @@ -6,7 +6,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter22.Listing22_05; public class Program { - readonly static object _Sync = new(); + static readonly object _Sync = new(); static int _Total = int.MaxValue; static int _Count = 0; diff --git a/src/Shared/Cryptographer.cs b/src/Shared/Cryptographer.cs index 82d315dc6..4cebc7f9b 100644 --- a/src/Shared/Cryptographer.cs +++ b/src/Shared/Cryptographer.cs @@ -36,7 +36,7 @@ public async Task EncryptAsync(string text, Stream outputFileStream) return await EncryptAsync(text, CryptoAlgorithm.CreateEncryptor(), outputFileStream); } - static public async Task EncryptAsync(string plainText, byte[] key, byte[] iv) + public static async Task EncryptAsync(string plainText, byte[] key, byte[] iv) { byte[] encrypted; // Create a new AesManaged. @@ -103,7 +103,7 @@ public async Task DecryptAsync(byte[] encryptedData, Stream outputStream) await DecryptAsync(encryptedData, CryptoAlgorithm.CreateDecryptor(), outputStream); } - static public async Task DecryptAsync(byte[] encryptedData, byte[] key, byte[] iV) + public static async Task DecryptAsync(byte[] encryptedData, byte[] key, byte[] iV) { string plaintext; // Create AesManaged diff --git a/src/Shared/Tests/PowerShellTestUtilities.cs b/src/Shared/Tests/PowerShellTestUtilities.cs index 9f1aedee0..35b9390d9 100644 --- a/src/Shared/Tests/PowerShellTestUtilities.cs +++ b/src/Shared/Tests/PowerShellTestUtilities.cs @@ -5,14 +5,14 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Shared.Tests; public class PowerShellTestUtilities { - private readonly static Mutex Mutext = new (false, typeof(PowerShellTestUtilities).FullName); + private static readonly Mutex Mutext = new (false, typeof(PowerShellTestUtilities).FullName); public static bool WindowsEnvironment() { return RuntimeInformation.IsOSPlatform(OSPlatform.Windows); } - private readonly static Lazy _PowerShellCommand = new(() => + private static readonly Lazy _PowerShellCommand = new(() => { string? powershellCommand = null; // Verify that the PowerShell command executes successfully.