From 3e3f87946de3f2000c9a24d5e2cbc26a9e594aab Mon Sep 17 00:00:00 2001 From: xtqqczze Date: Thu, 29 Oct 2020 02:38:06 +0000 Subject: [PATCH 1/8] Fix IDE0044: MakeFieldReadonly --- .../security/CertificateProvider.cs | 8 ++++---- .../engine/MshCmdlet.cs | 2 +- .../security/nativeMethods.cs | 14 +++++++------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs b/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs index ff66e7c9932..fa277e8ba01 100644 --- a/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs +++ b/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs @@ -127,12 +127,12 @@ public struct DnsNameRepresentation /// /// Punycode version of DNS name. /// - private string _punycodeName; + private readonly string _punycodeName; /// /// Unicode version of DNS name. /// - private string _unicodeName; + private readonly string _unicodeName; /// /// Ambiguous constructor of a DnsNameRepresentation. @@ -3068,12 +3068,12 @@ public struct EnhancedKeyUsageRepresentation /// /// Localized friendly name of EKU. /// - private string _friendlyName; + private readonly string _friendlyName; /// /// OID of EKU. /// - private string _oid; + private readonly string _oid; /// /// Constructor of an EnhancedKeyUsageRepresentation. diff --git a/src/System.Management.Automation/engine/MshCmdlet.cs b/src/System.Management.Automation/engine/MshCmdlet.cs index 113c3d39dbd..e3b86b6bcc6 100644 --- a/src/System.Management.Automation/engine/MshCmdlet.cs +++ b/src/System.Management.Automation/engine/MshCmdlet.cs @@ -70,7 +70,7 @@ public interface IDynamicParameters /// public struct SwitchParameter { - private bool _isPresent; + private readonly bool _isPresent; /// /// Returns true if the parameter was specified on the command line, false otherwise. /// diff --git a/src/System.Management.Automation/security/nativeMethods.cs b/src/System.Management.Automation/security/nativeMethods.cs index a48c430f234..b2adb1908c4 100644 --- a/src/System.Management.Automation/security/nativeMethods.cs +++ b/src/System.Management.Automation/security/nativeMethods.cs @@ -1957,16 +1957,16 @@ internal struct SIP_INDIRECT_DATA [StructLayout(LayoutKind.Sequential)] internal struct CRYPTCATCDF { - private DWORD _cbStruct; - private IntPtr _hFile; - private DWORD _dwCurFilePos; - private DWORD _dwLastMemberOffset; - private BOOL _fEOF; + private readonly DWORD _cbStruct; + private readonly IntPtr _hFile; + private readonly DWORD _dwCurFilePos; + private readonly DWORD _dwLastMemberOffset; + private readonly BOOL _fEOF; [MarshalAs(UnmanagedType.LPWStr)] - private string _pwszResultDir; + private readonly string _pwszResultDir; - private IntPtr _hCATStore; + private readonly IntPtr _hCATStore; }; [StructLayout(LayoutKind.Sequential)] From b16e94a1693446b3f3f7f2388bad6b4f4bde2a89 Mon Sep 17 00:00:00 2001 From: xtqqczze Date: Wed, 28 Oct 2020 23:49:58 +0000 Subject: [PATCH 2/8] Fix EPS01: Struct can be made readonly --- .../commands/management/ContentCommandBase.cs | 2 +- .../WindowsTaskbarJumpList/ComInterfaces.cs | 2 +- .../WindowsTaskbarJumpList/PropertyKey.cs | 2 +- .../DotNetCode/Eventing/EventDescriptor.cs | 2 +- .../security/CertificateProvider.cs | 4 ++-- .../engine/CommandCompletion/CommandCompletion.cs | 4 ++-- src/System.Management.Automation/engine/CommandInfo.cs | 2 +- src/System.Management.Automation/engine/LanguagePrimitives.cs | 2 +- src/System.Management.Automation/engine/MshCmdlet.cs | 2 +- src/System.Management.Automation/engine/MshMemberInfo.cs | 4 ++-- .../engine/interpreter/BranchLabel.cs | 2 +- .../engine/interpreter/InstructionList.cs | 4 ++-- .../engine/interpreter/LightCompiler.cs | 2 +- .../engine/interpreter/LocalVariables.cs | 2 +- .../engine/interpreter/Utilities.cs | 2 +- src/System.Management.Automation/engine/regex.cs | 2 +- src/System.Management.Automation/security/nativeMethods.cs | 2 +- 17 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/ContentCommandBase.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/ContentCommandBase.cs index b595c0195f9..31c6a3c7ba1 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/ContentCommandBase.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/ContentCommandBase.cs @@ -336,7 +336,7 @@ public PSObject AttachNotes(PSObject content) /// A struct to hold the path information and the content readers/writers /// for an item. /// - internal struct ContentHolder + internal readonly struct ContentHolder { internal ContentHolder( PathInfo pathInfo, diff --git a/src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/ComInterfaces.cs b/src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/ComInterfaces.cs index 761c6f6e26f..6ef638c865b 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/ComInterfaces.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/ComInterfaces.cs @@ -19,7 +19,7 @@ internal static class ComInterfaces /// string fields at all, nothing is lost. /// [StructLayout(LayoutKind.Sequential)] - internal struct StartUpInfo + internal readonly struct StartUpInfo { public readonly UInt32 cb; private readonly IntPtr lpReserved; diff --git a/src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/PropertyKey.cs b/src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/PropertyKey.cs index 6e12fcb0f63..ecd1918492b 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/PropertyKey.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/PropertyKey.cs @@ -10,7 +10,7 @@ namespace Microsoft.PowerShell /// Defines a unique key for a Shell Property. /// [StructLayout(LayoutKind.Sequential, Pack = 4)] - internal struct PropertyKey : IEquatable + internal readonly struct PropertyKey : IEquatable { #region Public Properties /// diff --git a/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventDescriptor.cs b/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventDescriptor.cs index f2329ae2fd6..723832979f8 100644 --- a/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventDescriptor.cs +++ b/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventDescriptor.cs @@ -8,7 +8,7 @@ namespace System.Diagnostics.Eventing { [StructLayout(LayoutKind.Explicit, Size = 16)] - public struct EventDescriptor + public readonly struct EventDescriptor { [FieldOffset(0)] private readonly ushort _id; diff --git a/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs b/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs index fa277e8ba01..feeb06703e3 100644 --- a/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs +++ b/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs @@ -122,7 +122,7 @@ public int ExpiringInDays /// The structure contains punycode name and unicode name. /// [SuppressMessage("Microsoft.Performance", "CA1815:OverrideEqualsAndOperatorEqualsOnValueTypes")] - public struct DnsNameRepresentation + public readonly struct DnsNameRepresentation { /// /// Punycode version of DNS name. @@ -3063,7 +3063,7 @@ public X509StoreLocation(StoreLocation location) /// The structure contains friendly name and EKU oid. /// [SuppressMessage("Microsoft.Performance", "CA1815:OverrideEqualsAndOperatorEqualsOnValueTypes")] - public struct EnhancedKeyUsageRepresentation + public readonly struct EnhancedKeyUsageRepresentation { /// /// Localized friendly name of EKU. diff --git a/src/System.Management.Automation/engine/CommandCompletion/CommandCompletion.cs b/src/System.Management.Automation/engine/CommandCompletion/CommandCompletion.cs index e00e0d737fc..bec089ab069 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CommandCompletion.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CommandCompletion.cs @@ -740,7 +740,7 @@ private static bool PSv2IsCommandLikeCmdlet(string lastWord, out bool isSnapinSp return false; } - private struct CommandAndName + private readonly struct CommandAndName { internal readonly PSObject Command; internal readonly PSSnapinQualifiedName CommandName; @@ -1067,7 +1067,7 @@ private static bool PSv2ShouldFullyQualifyPathsPath(PowerShellExecutionHelper he return isAbsolute; } - private struct PathItemAndConvertedPath + private readonly struct PathItemAndConvertedPath { internal readonly string Path; internal readonly PSObject Item; diff --git a/src/System.Management.Automation/engine/CommandInfo.cs b/src/System.Management.Automation/engine/CommandInfo.cs index fd98949eff0..7cc2063843f 100644 --- a/src/System.Management.Automation/engine/CommandInfo.cs +++ b/src/System.Management.Automation/engine/CommandInfo.cs @@ -904,7 +904,7 @@ public override string ToString() } [DebuggerDisplay("{PSTypeName} {Name}")] - internal struct PSMemberNameAndType + internal readonly struct PSMemberNameAndType { public readonly string Name; diff --git a/src/System.Management.Automation/engine/LanguagePrimitives.cs b/src/System.Management.Automation/engine/LanguagePrimitives.cs index 5929a5637e9..1ac3f5896d0 100644 --- a/src/System.Management.Automation/engine/LanguagePrimitives.cs +++ b/src/System.Management.Automation/engine/LanguagePrimitives.cs @@ -5109,7 +5109,7 @@ private static IConversionData FigureLanguageConversion(Type fromType, Type toTy return null; } - private struct SignatureComparator + private readonly struct SignatureComparator { private enum TypeMatchingContext { diff --git a/src/System.Management.Automation/engine/MshCmdlet.cs b/src/System.Management.Automation/engine/MshCmdlet.cs index e3b86b6bcc6..904ebe91d33 100644 --- a/src/System.Management.Automation/engine/MshCmdlet.cs +++ b/src/System.Management.Automation/engine/MshCmdlet.cs @@ -68,7 +68,7 @@ public interface IDynamicParameters /// Type used to define a parameter on a cmdlet script of function that /// can only be used as a switch. /// - public struct SwitchParameter + public readonly struct SwitchParameter { private readonly bool _isPresent; /// diff --git a/src/System.Management.Automation/engine/MshMemberInfo.cs b/src/System.Management.Automation/engine/MshMemberInfo.cs index ab1369822ea..b091c5fc3b8 100644 --- a/src/System.Management.Automation/engine/MshMemberInfo.cs +++ b/src/System.Management.Automation/engine/MshMemberInfo.cs @@ -2748,11 +2748,11 @@ internal class PSOutParameter { } - internal struct PSPointer + internal readonly struct PSPointer { } - internal struct PSTypedReference + internal readonly struct PSTypedReference { } diff --git a/src/System.Management.Automation/engine/interpreter/BranchLabel.cs b/src/System.Management.Automation/engine/interpreter/BranchLabel.cs index 919a7b06106..08af974416c 100644 --- a/src/System.Management.Automation/engine/interpreter/BranchLabel.cs +++ b/src/System.Management.Automation/engine/interpreter/BranchLabel.cs @@ -19,7 +19,7 @@ namespace System.Management.Automation.Interpreter { - internal struct RuntimeLabel + internal readonly struct RuntimeLabel { public readonly int Index; public readonly int StackDepth; diff --git a/src/System.Management.Automation/engine/interpreter/InstructionList.cs b/src/System.Management.Automation/engine/interpreter/InstructionList.cs index 9617c746359..e9e6ee6ea18 100644 --- a/src/System.Management.Automation/engine/interpreter/InstructionList.cs +++ b/src/System.Management.Automation/engine/interpreter/InstructionList.cs @@ -24,7 +24,7 @@ namespace System.Management.Automation.Interpreter { [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1815:OverrideEqualsAndOperatorEqualsOnValueTypes")] [DebuggerTypeProxy(typeof(InstructionArray.DebugView))] - internal struct InstructionArray + internal readonly struct InstructionArray { internal readonly int MaxStackDepth; internal readonly int MaxContinuationDepth; @@ -156,7 +156,7 @@ internal static InstructionView[] GetInstructionViews(IList instruc } [DebuggerDisplay("{GetValue(),nq}", Name = "{GetName(),nq}", Type = "{GetDisplayType(), nq}")] - internal struct InstructionView + internal readonly struct InstructionView { private readonly int _index; private readonly int _stackDepth; diff --git a/src/System.Management.Automation/engine/interpreter/LightCompiler.cs b/src/System.Management.Automation/engine/interpreter/LightCompiler.cs index e5d399bf480..57dd716f2d8 100644 --- a/src/System.Management.Automation/engine/interpreter/LightCompiler.cs +++ b/src/System.Management.Automation/engine/interpreter/LightCompiler.cs @@ -243,7 +243,7 @@ public override string ToString() // TODO: [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1815:OverrideEqualsAndOperatorEqualsOnValueTypes")] [Serializable] - internal struct InterpretedFrameInfo + internal readonly struct InterpretedFrameInfo { public readonly string MethodName; diff --git a/src/System.Management.Automation/engine/interpreter/LocalVariables.cs b/src/System.Management.Automation/engine/interpreter/LocalVariables.cs index e093877ce34..aaee75d0234 100644 --- a/src/System.Management.Automation/engine/interpreter/LocalVariables.cs +++ b/src/System.Management.Automation/engine/interpreter/LocalVariables.cs @@ -78,7 +78,7 @@ public override string ToString() } } - internal struct LocalDefinition + internal readonly struct LocalDefinition { private readonly int _index; private readonly ParameterExpression _parameter; diff --git a/src/System.Management.Automation/engine/interpreter/Utilities.cs b/src/System.Management.Automation/engine/interpreter/Utilities.cs index 810dea30d1a..7a1e29a0e6b 100644 --- a/src/System.Management.Automation/engine/interpreter/Utilities.cs +++ b/src/System.Management.Automation/engine/interpreter/Utilities.cs @@ -668,7 +668,7 @@ public TValue this[TKey key] } } - private struct KeyInfo + private readonly struct KeyInfo { internal readonly TValue Value; internal readonly LinkedListNode List; diff --git a/src/System.Management.Automation/engine/regex.cs b/src/System.Management.Automation/engine/regex.cs index c867f355158..64a7deed796 100644 --- a/src/System.Management.Automation/engine/regex.cs +++ b/src/System.Management.Automation/engine/regex.cs @@ -1264,7 +1264,7 @@ protected override void EndBracketExpression() } } - private struct CharacterNormalizer + private readonly struct CharacterNormalizer { private readonly CultureInfo _cultureInfo; private readonly bool _caseInsensitive; diff --git a/src/System.Management.Automation/security/nativeMethods.cs b/src/System.Management.Automation/security/nativeMethods.cs index b2adb1908c4..023b8144e57 100644 --- a/src/System.Management.Automation/security/nativeMethods.cs +++ b/src/System.Management.Automation/security/nativeMethods.cs @@ -1955,7 +1955,7 @@ internal struct SIP_INDIRECT_DATA } [StructLayout(LayoutKind.Sequential)] - internal struct CRYPTCATCDF + internal readonly struct CRYPTCATCDF { private readonly DWORD _cbStruct; private readonly IntPtr _hFile; From e3fde33ffb641a8b509c4ec760f28ed239bdeb97 Mon Sep 17 00:00:00 2001 From: xtqqczze Date: Thu, 29 Oct 2020 00:02:11 +0000 Subject: [PATCH 3/8] Fix EPS05: Use in-modifier for passing a readonly struct --- .../commands/management/GetContentCommand.cs | 2 +- src/System.Management.Automation/engine/CommandInfo.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs index 86f252fb8fc..3a363bead6d 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs @@ -277,7 +277,7 @@ protected override void ProcessRecord() /// true if no error occured /// false if there was an error /// - private bool ScanForwardsForTail(ContentHolder holder, CmdletProviderContext currentContext) + private bool ScanForwardsForTail(in ContentHolder holder, CmdletProviderContext currentContext) { var fsReader = holder.Reader as FileSystemContentReaderWriter; Dbg.Diagnostics.Assert(fsReader != null, "Tail is only supported for FileSystemContentReaderWriter"); diff --git a/src/System.Management.Automation/engine/CommandInfo.cs b/src/System.Management.Automation/engine/CommandInfo.cs index 7cc2063843f..063ba030ede 100644 --- a/src/System.Management.Automation/engine/CommandInfo.cs +++ b/src/System.Management.Automation/engine/CommandInfo.cs @@ -960,7 +960,7 @@ private PSSyntheticTypeName(string typeName, Type type, IList member.Name.Equals(nameof(PSTypeName), StringComparison.OrdinalIgnoreCase); + private static bool IsPSTypeName(in PSMemberNameAndType member) => member.Name.Equals(nameof(PSTypeName), StringComparison.OrdinalIgnoreCase); private static string GetMemberTypeProjection(string typename, IList members) { From 458d2e6fb8228cc5e79f60ba563eb3d0088271f8 Mon Sep 17 00:00:00 2001 From: xtqqczze Date: Thu, 29 Oct 2020 00:12:47 +0000 Subject: [PATCH 4/8] Fix IDE0044: MakeFieldReadonly --- .../utils/tracing/EtwActivity.cs | 2 +- .../utils/tracing/TracingGen.cs | 164 +++++++++--------- 2 files changed, 83 insertions(+), 83 deletions(-) diff --git a/src/System.Management.Automation/utils/tracing/EtwActivity.cs b/src/System.Management.Automation/utils/tracing/EtwActivity.cs index a29e7284717..e67132cf788 100644 --- a/src/System.Management.Automation/utils/tracing/EtwActivity.cs +++ b/src/System.Management.Automation/utils/tracing/EtwActivity.cs @@ -255,7 +255,7 @@ public void Callback(IAsyncResult asyncResult) private static Dictionary providers = new Dictionary(); private static object syncLock = new object(); - private static EventDescriptor _WriteTransferEvent = new EventDescriptor(0x1f05, 0x1, 0x11, 0x5, 0x14, 0x0, (long)0x4000000000000000); + private static readonly EventDescriptor _WriteTransferEvent = new EventDescriptor(0x1f05, 0x1, 0x11, 0x5, 0x14, 0x0, (long)0x4000000000000000); private EventProvider currentProvider; diff --git a/src/System.Management.Automation/utils/tracing/TracingGen.cs b/src/System.Management.Automation/utils/tracing/TracingGen.cs index ea369e4513a..d6d5f5070bb 100644 --- a/src/System.Management.Automation/utils/tracing/TracingGen.cs +++ b/src/System.Management.Automation/utils/tracing/TracingGen.cs @@ -38,88 +38,88 @@ public sealed partial class Tracer : System.Management.Automation.Tracing.EtwAct public const long KeywordAll = 0xFFFFFFFF; private static Guid providerId = Guid.Parse("a0c1853b-5c40-4b15-8766-3cf1c58f985a"); - private static EventDescriptor WriteTransferEventEvent; - private static EventDescriptor DebugMessageEvent; - private static EventDescriptor M3PAbortingWorkflowExecutionEvent; - private static EventDescriptor M3PActivityExecutionFinishedEvent; - private static EventDescriptor M3PActivityExecutionQueuedEvent; - private static EventDescriptor M3PActivityExecutionStartedEvent; - private static EventDescriptor M3PBeginContainerParentJobExecutionEvent; - private static EventDescriptor M3PBeginCreateNewJobEvent; - private static EventDescriptor M3PBeginJobLogicEvent; - private static EventDescriptor M3PBeginProxyChildJobEventHandlerEvent; - private static EventDescriptor M3PBeginProxyJobEventHandlerEvent; - private static EventDescriptor M3PBeginProxyJobExecutionEvent; - private static EventDescriptor M3PBeginRunGarbageCollectionEvent; - private static EventDescriptor M3PBeginStartWorkflowApplicationEvent; - private static EventDescriptor M3PBeginWorkflowExecutionEvent; - private static EventDescriptor M3PCancellingWorkflowExecutionEvent; - private static EventDescriptor M3PChildWorkflowJobAdditionEvent; - private static EventDescriptor M3PEndContainerParentJobExecutionEvent; - private static EventDescriptor M3PEndCreateNewJobEvent; - private static EventDescriptor M3PEndJobLogicEvent; - private static EventDescriptor M3PEndpointDisabledEvent; - private static EventDescriptor M3PEndpointEnabledEvent; - private static EventDescriptor M3PEndpointModifiedEvent; - private static EventDescriptor M3PEndpointRegisteredEvent; - private static EventDescriptor M3PEndpointUnregisteredEvent; - private static EventDescriptor M3PEndProxyChildJobEventHandlerEvent; - private static EventDescriptor M3PEndProxyJobEventHandlerEvent; - private static EventDescriptor M3PEndProxyJobExecutionEvent; - private static EventDescriptor M3PEndRunGarbageCollectionEvent; - private static EventDescriptor M3PEndStartWorkflowApplicationEvent; - private static EventDescriptor M3PEndWorkflowExecutionEvent; - private static EventDescriptor M3PErrorImportingWorkflowFromXamlEvent; - private static EventDescriptor M3PForcedWorkflowShutdownErrorEvent; - private static EventDescriptor M3PForcedWorkflowShutdownFinishedEvent; - private static EventDescriptor M3PForcedWorkflowShutdownStartedEvent; - private static EventDescriptor M3PImportedWorkflowFromXamlEvent; - private static EventDescriptor M3PImportingWorkflowFromXamlEvent; - private static EventDescriptor M3PJobCreationCompleteEvent; - private static EventDescriptor M3PJobErrorEvent; - private static EventDescriptor M3PJobRemovedEvent; - private static EventDescriptor M3PJobRemoveErrorEvent; - private static EventDescriptor M3PJobStateChangedEvent; - private static EventDescriptor M3PLoadingWorkflowForExecutionEvent; - private static EventDescriptor M3POutOfProcessRunspaceStartedEvent; - private static EventDescriptor M3PParameterSplattingWasPerformedEvent; - private static EventDescriptor M3PParentJobCreatedEvent; - private static EventDescriptor M3PPersistenceStoreMaxSizeReachedEvent; - private static EventDescriptor M3PPersistingWorkflowEvent; - private static EventDescriptor M3PProxyJobRemoteJobAssociationEvent; - private static EventDescriptor M3PRemoveJobStartedEvent; - private static EventDescriptor M3PRunspaceAvailabilityChangedEvent; - private static EventDescriptor M3PRunspaceStateChangedEvent; - private static EventDescriptor M3PTrackingGuidContainerParentJobCorrelationEvent; - private static EventDescriptor M3PUnloadingWorkflowEvent; - private static EventDescriptor M3PWorkflowActivityExecutionFailedEvent; - private static EventDescriptor M3PWorkflowActivityValidatedEvent; - private static EventDescriptor M3PWorkflowActivityValidationFailedEvent; - private static EventDescriptor M3PWorkflowCleanupPerformedEvent; - private static EventDescriptor M3PWorkflowDeletedFromDiskEvent; - private static EventDescriptor M3PWorkflowEngineStartedEvent; - private static EventDescriptor M3PWorkflowExecutionAbortedEvent; - private static EventDescriptor M3PWorkflowExecutionCancelledEvent; - private static EventDescriptor M3PWorkflowExecutionErrorEvent; - private static EventDescriptor M3PWorkflowExecutionFinishedEvent; - private static EventDescriptor M3PWorkflowExecutionStartedEvent; - private static EventDescriptor M3PWorkflowJobCreatedEvent; - private static EventDescriptor M3PWorkflowLoadedForExecutionEvent; - private static EventDescriptor M3PWorkflowLoadedFromDiskEvent; - private static EventDescriptor M3PWorkflowManagerCheckpointEvent; - private static EventDescriptor M3PWorkflowPersistedEvent; - private static EventDescriptor M3PWorkflowPluginRequestedToShutdownEvent; - private static EventDescriptor M3PWorkflowPluginRestartedEvent; - private static EventDescriptor M3PWorkflowPluginStartedEvent; - private static EventDescriptor M3PWorkflowQuotaViolatedEvent; - private static EventDescriptor M3PWorkflowResumedEvent; - private static EventDescriptor M3PWorkflowResumingEvent; - private static EventDescriptor M3PWorkflowRunspacePoolCreatedEvent; - private static EventDescriptor M3PWorkflowStateChangedEvent; - private static EventDescriptor M3PWorkflowUnloadedEvent; - private static EventDescriptor M3PWorkflowValidationErrorEvent; - private static EventDescriptor M3PWorkflowValidationFinishedEvent; - private static EventDescriptor M3PWorkflowValidationStartedEvent; + private static readonly EventDescriptor WriteTransferEventEvent; + private static readonly EventDescriptor DebugMessageEvent; + private static readonly EventDescriptor M3PAbortingWorkflowExecutionEvent; + private static readonly EventDescriptor M3PActivityExecutionFinishedEvent; + private static readonly EventDescriptor M3PActivityExecutionQueuedEvent; + private static readonly EventDescriptor M3PActivityExecutionStartedEvent; + private static readonly EventDescriptor M3PBeginContainerParentJobExecutionEvent; + private static readonly EventDescriptor M3PBeginCreateNewJobEvent; + private static readonly EventDescriptor M3PBeginJobLogicEvent; + private static readonly EventDescriptor M3PBeginProxyChildJobEventHandlerEvent; + private static readonly EventDescriptor M3PBeginProxyJobEventHandlerEvent; + private static readonly EventDescriptor M3PBeginProxyJobExecutionEvent; + private static readonly EventDescriptor M3PBeginRunGarbageCollectionEvent; + private static readonly EventDescriptor M3PBeginStartWorkflowApplicationEvent; + private static readonly EventDescriptor M3PBeginWorkflowExecutionEvent; + private static readonly EventDescriptor M3PCancellingWorkflowExecutionEvent; + private static readonly EventDescriptor M3PChildWorkflowJobAdditionEvent; + private static readonly EventDescriptor M3PEndContainerParentJobExecutionEvent; + private static readonly EventDescriptor M3PEndCreateNewJobEvent; + private static readonly EventDescriptor M3PEndJobLogicEvent; + private static readonly EventDescriptor M3PEndpointDisabledEvent; + private static readonly EventDescriptor M3PEndpointEnabledEvent; + private static readonly EventDescriptor M3PEndpointModifiedEvent; + private static readonly EventDescriptor M3PEndpointRegisteredEvent; + private static readonly EventDescriptor M3PEndpointUnregisteredEvent; + private static readonly EventDescriptor M3PEndProxyChildJobEventHandlerEvent; + private static readonly EventDescriptor M3PEndProxyJobEventHandlerEvent; + private static readonly EventDescriptor M3PEndProxyJobExecutionEvent; + private static readonly EventDescriptor M3PEndRunGarbageCollectionEvent; + private static readonly EventDescriptor M3PEndStartWorkflowApplicationEvent; + private static readonly EventDescriptor M3PEndWorkflowExecutionEvent; + private static readonly EventDescriptor M3PErrorImportingWorkflowFromXamlEvent; + private static readonly EventDescriptor M3PForcedWorkflowShutdownErrorEvent; + private static readonly EventDescriptor M3PForcedWorkflowShutdownFinishedEvent; + private static readonly EventDescriptor M3PForcedWorkflowShutdownStartedEvent; + private static readonly EventDescriptor M3PImportedWorkflowFromXamlEvent; + private static readonly EventDescriptor M3PImportingWorkflowFromXamlEvent; + private static readonly EventDescriptor M3PJobCreationCompleteEvent; + private static readonly EventDescriptor M3PJobErrorEvent; + private static readonly EventDescriptor M3PJobRemovedEvent; + private static readonly EventDescriptor M3PJobRemoveErrorEvent; + private static readonly EventDescriptor M3PJobStateChangedEvent; + private static readonly EventDescriptor M3PLoadingWorkflowForExecutionEvent; + private static readonly EventDescriptor M3POutOfProcessRunspaceStartedEvent; + private static readonly EventDescriptor M3PParameterSplattingWasPerformedEvent; + private static readonly EventDescriptor M3PParentJobCreatedEvent; + private static readonly EventDescriptor M3PPersistenceStoreMaxSizeReachedEvent; + private static readonly EventDescriptor M3PPersistingWorkflowEvent; + private static readonly EventDescriptor M3PProxyJobRemoteJobAssociationEvent; + private static readonly EventDescriptor M3PRemoveJobStartedEvent; + private static readonly EventDescriptor M3PRunspaceAvailabilityChangedEvent; + private static readonly EventDescriptor M3PRunspaceStateChangedEvent; + private static readonly EventDescriptor M3PTrackingGuidContainerParentJobCorrelationEvent; + private static readonly EventDescriptor M3PUnloadingWorkflowEvent; + private static readonly EventDescriptor M3PWorkflowActivityExecutionFailedEvent; + private static readonly EventDescriptor M3PWorkflowActivityValidatedEvent; + private static readonly EventDescriptor M3PWorkflowActivityValidationFailedEvent; + private static readonly EventDescriptor M3PWorkflowCleanupPerformedEvent; + private static readonly EventDescriptor M3PWorkflowDeletedFromDiskEvent; + private static readonly EventDescriptor M3PWorkflowEngineStartedEvent; + private static readonly EventDescriptor M3PWorkflowExecutionAbortedEvent; + private static readonly EventDescriptor M3PWorkflowExecutionCancelledEvent; + private static readonly EventDescriptor M3PWorkflowExecutionErrorEvent; + private static readonly EventDescriptor M3PWorkflowExecutionFinishedEvent; + private static readonly EventDescriptor M3PWorkflowExecutionStartedEvent; + private static readonly EventDescriptor M3PWorkflowJobCreatedEvent; + private static readonly EventDescriptor M3PWorkflowLoadedForExecutionEvent; + private static readonly EventDescriptor M3PWorkflowLoadedFromDiskEvent; + private static readonly EventDescriptor M3PWorkflowManagerCheckpointEvent; + private static readonly EventDescriptor M3PWorkflowPersistedEvent; + private static readonly EventDescriptor M3PWorkflowPluginRequestedToShutdownEvent; + private static readonly EventDescriptor M3PWorkflowPluginRestartedEvent; + private static readonly EventDescriptor M3PWorkflowPluginStartedEvent; + private static readonly EventDescriptor M3PWorkflowQuotaViolatedEvent; + private static readonly EventDescriptor M3PWorkflowResumedEvent; + private static readonly EventDescriptor M3PWorkflowResumingEvent; + private static readonly EventDescriptor M3PWorkflowRunspacePoolCreatedEvent; + private static readonly EventDescriptor M3PWorkflowStateChangedEvent; + private static readonly EventDescriptor M3PWorkflowUnloadedEvent; + private static readonly EventDescriptor M3PWorkflowValidationErrorEvent; + private static readonly EventDescriptor M3PWorkflowValidationFinishedEvent; + private static readonly EventDescriptor M3PWorkflowValidationStartedEvent; /// /// Static constructor. From 656a10134a08fe7fefebacb406dc1b227c9bad77 Mon Sep 17 00:00:00 2001 From: xtqqczze Date: Thu, 29 Oct 2020 01:21:02 +0000 Subject: [PATCH 5/8] Replace ref-modifier with in-modifier in method signatures --- .../WindowsTaskbarJumpList/ComInterfaces.cs | 4 ++-- .../DotNetCode/Eventing/EventProvider.cs | 10 +++++----- .../DotNetCode/Eventing/UnsafeNativeMethods.cs | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/ComInterfaces.cs b/src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/ComInterfaces.cs index 6ef638c865b..7a8d4d83001 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/ComInterfaces.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/ComInterfaces.cs @@ -138,7 +138,7 @@ internal interface IPropertyStore /// /// [PreserveSig] - HResult GetValue([In] ref PropertyKey key, [Out] PropVariant pv); + HResult GetValue([In] in PropertyKey key, [Out] PropVariant pv); /// /// Sets the value of a property in the store. @@ -147,7 +147,7 @@ internal interface IPropertyStore /// /// [PreserveSig] - HResult SetValue([In] ref PropertyKey key, [In] PropVariant pv); + HResult SetValue([In] in PropertyKey key, [In] PropVariant pv); /// /// Commits the changes. diff --git a/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventProvider.cs b/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventProvider.cs index a1eba143e28..b101c78ee76 100644 --- a/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventProvider.cs +++ b/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventProvider.cs @@ -488,7 +488,7 @@ public bool WriteMessageEvent(string eventMessage) /// /// /// - public bool WriteEvent(ref EventDescriptor eventDescriptor, params object[] eventPayload) + public bool WriteEvent(in EventDescriptor eventDescriptor, params object[] eventPayload) { return WriteTransferEvent(ref eventDescriptor, Guid.Empty, eventPayload); } @@ -504,7 +504,7 @@ public bool WriteEvent(ref EventDescriptor eventDescriptor, params object[] even /// [System.Security.SecurityCritical] [SuppressMessage("Microsoft.Usage", "CA2208:InstantiateArgumentExceptionsCorrectly")] - public bool WriteEvent(ref EventDescriptor eventDescriptor, string data) + public bool WriteEvent(in EventDescriptor eventDescriptor, string data) { uint status = 0; @@ -565,7 +565,7 @@ public bool WriteEvent(ref EventDescriptor eventDescriptor, string data) /// pointer do the event data /// [System.Security.SecurityCritical] - protected bool WriteEvent(ref EventDescriptor eventDescriptor, int dataCount, IntPtr data) + protected bool WriteEvent(in EventDescriptor eventDescriptor, int dataCount, IntPtr data) { uint status = 0; @@ -602,7 +602,7 @@ protected bool WriteEvent(ref EventDescriptor eventDescriptor, int dataCount, In /// /// [System.Security.SecurityCritical] - public bool WriteTransferEvent(ref EventDescriptor eventDescriptor, Guid relatedActivityId, params object[] eventPayload) + public bool WriteTransferEvent(in EventDescriptor eventDescriptor, Guid relatedActivityId, params object[] eventPayload) { uint status = 0; @@ -737,7 +737,7 @@ public bool WriteTransferEvent(ref EventDescriptor eventDescriptor, Guid related } [System.Security.SecurityCritical] - protected bool WriteTransferEvent(ref EventDescriptor eventDescriptor, Guid relatedActivityId, int dataCount, IntPtr data) + protected bool WriteTransferEvent(in EventDescriptor eventDescriptor, Guid relatedActivityId, int dataCount, IntPtr data) { uint status = 0; diff --git a/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/UnsafeNativeMethods.cs b/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/UnsafeNativeMethods.cs index 5da8809897d..26455c86adf 100644 --- a/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/UnsafeNativeMethods.cs +++ b/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/UnsafeNativeMethods.cs @@ -133,7 +133,7 @@ [In][Out]ref long registrationHandle // Control (Is Enabled) APIs [DllImport(EventProviderDllName, ExactSpelling = true, EntryPoint = "EventEnabled", CharSet = System.Runtime.InteropServices.CharSet.Unicode)] [SecurityCritical] - internal static extern int EventEnabled([In] long registrationHandle, [In] ref System.Diagnostics.Eventing.EventDescriptor eventDescriptor); + internal static extern int EventEnabled([In] long registrationHandle, [In] in System.Diagnostics.Eventing.EventDescriptor eventDescriptor); [DllImport(EventProviderDllName, ExactSpelling = true, EntryPoint = "EventProviderEnabled", CharSet = System.Runtime.InteropServices.CharSet.Unicode)] [SecurityCritical] @@ -144,7 +144,7 @@ [In][Out]ref long registrationHandle [SecurityCritical] internal static extern unsafe uint EventWrite( [In] long registrationHandle, - [In] ref EventDescriptor eventDescriptor, + [In] in EventDescriptor eventDescriptor, [In] uint userDataCount, [In] void* userData ); @@ -163,7 +163,7 @@ [In] void* userData [SecurityCritical] internal static extern unsafe uint EventWriteTransfer( [In] long registrationHandle, - [In] ref EventDescriptor eventDescriptor, + [In] in EventDescriptor eventDescriptor, [In] Guid* activityId, [In] Guid* relatedActivityId, [In] uint userDataCount, From bd43a694570901b5d6c1993e521545346345f038 Mon Sep 17 00:00:00 2001 From: xtqqczze Date: Thu, 29 Oct 2020 01:23:34 +0000 Subject: [PATCH 6/8] Fix CS8329 --- .../DotNetCode/Eventing/EventProvider.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventProvider.cs b/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventProvider.cs index b101c78ee76..75731eea659 100644 --- a/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventProvider.cs +++ b/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventProvider.cs @@ -490,7 +490,7 @@ public bool WriteMessageEvent(string eventMessage) /// public bool WriteEvent(in EventDescriptor eventDescriptor, params object[] eventPayload) { - return WriteTransferEvent(ref eventDescriptor, Guid.Empty, eventPayload); + return WriteTransferEvent(in eventDescriptor, Guid.Empty, eventPayload); } /// @@ -534,7 +534,7 @@ public bool WriteEvent(in EventDescriptor eventDescriptor, string data) userData.DataPointer = (ulong)pdata; status = UnsafeNativeMethods.EventWriteTransfer(_regHandle, - ref eventDescriptor, + in eventDescriptor, (activityId == Guid.Empty) ? null : &activityId, null, 1, @@ -575,7 +575,7 @@ protected bool WriteEvent(in EventDescriptor eventDescriptor, int dataCount, Int status = UnsafeNativeMethods.EventWriteTransfer( _regHandle, - ref eventDescriptor, + in eventDescriptor, (activityId == Guid.Empty) ? null : &activityId, null, (uint)dataCount, @@ -719,7 +719,7 @@ public bool WriteTransferEvent(in EventDescriptor eventDescriptor, Guid relatedA } status = UnsafeNativeMethods.EventWriteTransfer(_regHandle, - ref eventDescriptor, + in eventDescriptor, (activityId == Guid.Empty) ? null : &activityId, (relatedActivityId == Guid.Empty) ? null : &relatedActivityId, (uint)argCount, @@ -747,7 +747,7 @@ protected bool WriteTransferEvent(in EventDescriptor eventDescriptor, Guid relat { status = UnsafeNativeMethods.EventWriteTransfer( _regHandle, - ref eventDescriptor, + in eventDescriptor, (activityId == Guid.Empty) ? null : &activityId, &relatedActivityId, (uint)dataCount, From 301f0833fe5b7a20520d1fcad086c6d984ca368a Mon Sep 17 00:00:00 2001 From: xtqqczze Date: Thu, 29 Oct 2020 01:32:26 +0000 Subject: [PATCH 7/8] Fix CS1615 --- .../NewWinEventCommand.cs | 4 ++-- .../WindowsTaskbarJumpList/TaskbarJumpList.cs | 2 +- src/System.Management.Automation/utils/PowerShellETWTracer.cs | 2 +- src/System.Management.Automation/utils/tracing/EtwActivity.cs | 4 ++-- .../utils/tracing/EtwEventCorrelator.cs | 2 +- .../utils/tracing/PSEtwLogProvider.cs | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Diagnostics/NewWinEventCommand.cs b/src/Microsoft.PowerShell.Commands.Diagnostics/NewWinEventCommand.cs index 216e9bca7ea..a551b833871 100644 --- a/src/Microsoft.PowerShell.Commands.Diagnostics/NewWinEventCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Diagnostics/NewWinEventCommand.cs @@ -328,11 +328,11 @@ protected override void ProcessRecord() } } - provider.WriteEvent(ref ed, _payload); + provider.WriteEvent(in ed, _payload); } else { - provider.WriteEvent(ref ed); + provider.WriteEvent(in ed); } } diff --git a/src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/TaskbarJumpList.cs b/src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/TaskbarJumpList.cs index 5b7572c94b2..1280c47695d 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/TaskbarJumpList.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/TaskbarJumpList.cs @@ -97,7 +97,7 @@ private static void CreateElevatedEntry(string title) flags |= 0x00002000; // SLDF_RUNAS_USER shellLinkDataList.SetFlags(flags); var PKEY_TITLE = new PropertyKey(new Guid("{F29F85E0-4FF9-1068-AB91-08002B27B3D9}"), 2); - hResult = nativePropertyStore.SetValue(ref PKEY_TITLE, new PropVariant(title)); + hResult = nativePropertyStore.SetValue(in PKEY_TITLE, new PropVariant(title)); if (hResult < 0) { pCustDestList.AbortList(); diff --git a/src/System.Management.Automation/utils/PowerShellETWTracer.cs b/src/System.Management.Automation/utils/PowerShellETWTracer.cs index 7631d760b2d..2b13e9a8414 100644 --- a/src/System.Management.Automation/utils/PowerShellETWTracer.cs +++ b/src/System.Management.Automation/utils/PowerShellETWTracer.cs @@ -866,7 +866,7 @@ private bool Trace(PowerShellTraceEvent traceEvent, PowerShellTraceLevel level, } } - return _provider.WriteEvent(ref ed, args); + return _provider.WriteEvent(in ed, args); } /// diff --git a/src/System.Management.Automation/utils/tracing/EtwActivity.cs b/src/System.Management.Automation/utils/tracing/EtwActivity.cs index e67132cf788..6956b7a1898 100644 --- a/src/System.Management.Automation/utils/tracing/EtwActivity.cs +++ b/src/System.Management.Automation/utils/tracing/EtwActivity.cs @@ -328,7 +328,7 @@ public void CorrelateWithActivity(Guid parentActivityId) if (parentActivityId != Guid.Empty) { EventDescriptor transferEvent = TransferEvent; - provider.WriteTransferEvent(ref transferEvent, parentActivityId, activityId, parentActivityId); + provider.WriteTransferEvent(in transferEvent, parentActivityId, activityId, parentActivityId); } } @@ -473,7 +473,7 @@ protected void WriteEvent(EventDescriptor ed, params object[] payload) } } - bool success = provider.WriteEvent(ref ed, payload); + bool success = provider.WriteEvent(in ed, payload); if (EventWritten != null) { EventWritten.Invoke(this, new EtwEventArgs(ed, success, payload)); diff --git a/src/System.Management.Automation/utils/tracing/EtwEventCorrelator.cs b/src/System.Management.Automation/utils/tracing/EtwEventCorrelator.cs index 4895a582223..ae9dbb9c415 100644 --- a/src/System.Management.Automation/utils/tracing/EtwEventCorrelator.cs +++ b/src/System.Management.Automation/utils/tracing/EtwEventCorrelator.cs @@ -98,7 +98,7 @@ public IEtwActivityReverter StartActivity(Guid relatedActivityId) if (relatedActivityId != Guid.Empty) { var tempTransferEvent = _transferEvent; - _transferProvider.WriteTransferEvent(ref tempTransferEvent, relatedActivityId); + _transferProvider.WriteTransferEvent(in tempTransferEvent, relatedActivityId); } return retActivity; diff --git a/src/System.Management.Automation/utils/tracing/PSEtwLogProvider.cs b/src/System.Management.Automation/utils/tracing/PSEtwLogProvider.cs index b9581755dd5..9d2f9356123 100755 --- a/src/System.Management.Automation/utils/tracing/PSEtwLogProvider.cs +++ b/src/System.Management.Automation/utils/tracing/PSEtwLogProvider.cs @@ -284,7 +284,7 @@ internal void WriteEvent(PSEventId id, PSChannel channel, PSOpcode opcode, PSLev EventDescriptor desc = new EventDescriptor((int)id, (byte)PSEventVersion.One, (byte)channel, (byte)level, (byte)opcode, (int)task, longKeyword); - etwProvider.WriteEvent(ref desc, args); + etwProvider.WriteEvent(in desc, args); } /// @@ -292,7 +292,7 @@ internal void WriteEvent(PSEventId id, PSChannel channel, PSOpcode opcode, PSLev /// internal void WriteTransferEvent(Guid parentActivityId) { - etwProvider.WriteTransferEvent(ref _xferEventDescriptor, parentActivityId, EtwActivity.GetActivityId(), parentActivityId); + etwProvider.WriteTransferEvent(in _xferEventDescriptor, parentActivityId, EtwActivity.GetActivityId(), parentActivityId); } /// From be4526738936be32c2159642edfa1528a004a2b0 Mon Sep 17 00:00:00 2001 From: xtqqczze Date: Thu, 29 Oct 2020 02:49:38 +0000 Subject: [PATCH 8/8] Revert addition of readonly modifier for no-member types --- src/System.Management.Automation/engine/MshMemberInfo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/System.Management.Automation/engine/MshMemberInfo.cs b/src/System.Management.Automation/engine/MshMemberInfo.cs index b091c5fc3b8..ab1369822ea 100644 --- a/src/System.Management.Automation/engine/MshMemberInfo.cs +++ b/src/System.Management.Automation/engine/MshMemberInfo.cs @@ -2748,11 +2748,11 @@ internal class PSOutParameter { } - internal readonly struct PSPointer + internal struct PSPointer { } - internal readonly struct PSTypedReference + internal struct PSTypedReference { }