From 52ecb6d18e4413e5aecd6e36b40cadaf73eb5123 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Wed, 4 Nov 2020 19:13:56 +0000 Subject: [PATCH] Run `dotnet-format` to improve formatting of source code (#13503) --- .../PdhHelper.cs | 2 +- .../commands/management/Process.cs | 142 +++++++++--------- .../host/msh/ManagedEntrance.cs | 4 +- .../Eventing/UnsafeNativeMethods.cs | 56 +++---- .../CoreCLR/CorePsAssemblyLoadContext.cs | 2 +- .../CoreCLR/CorePsPlatform.cs | 20 +-- .../engine/COM/ComDispatch.cs | 2 +- .../engine/ComInterop/VariantArray.cs | 2 +- .../engine/Modules/ImportModuleCommand.cs | 4 +- .../engine/ReflectionParameterBinder.cs | 9 +- .../CommandPrediction/CommandPrediction.cs | 3 +- .../engine/remoting/fanin/WSManNativeAPI.cs | 22 +-- .../engine/remoting/fanin/WSManPlugin.cs | 8 +- .../namespaces/FileSystemProvider.cs | 2 +- .../namespaces/RegistryProvider.cs | 8 +- .../security/SecureStringHelper.cs | 24 +-- .../security/SecurityManager.cs | 8 +- .../security/SecuritySupport.cs | 8 +- .../security/nativeMethods.cs | 2 +- .../utils/CryptoUtils.cs | 4 +- 20 files changed, 172 insertions(+), 160 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Diagnostics/PdhHelper.cs b/src/Microsoft.PowerShell.Commands.Diagnostics/PdhHelper.cs index df37fbd802..f4013cd87e 100644 --- a/src/Microsoft.PowerShell.Commands.Diagnostics/PdhHelper.cs +++ b/src/Microsoft.PowerShell.Commands.Diagnostics/PdhHelper.cs @@ -375,7 +375,7 @@ namespace Microsoft.Powershell.Commands.GetCounter.PdhNative private static extern uint PdhValidatePath(string szFullPathBuffer); [DllImport("pdh.dll", CharSet = CharSet.Unicode)] - private static extern uint PdhGetCounterInfo(IntPtr hCounter, [MarshalAs(UnmanagedType.U1)]bool bRetrieveExplainText, ref IntPtr pdwBufferSize, IntPtr lpBuffer); + private static extern uint PdhGetCounterInfo(IntPtr hCounter, [MarshalAs(UnmanagedType.U1)] bool bRetrieveExplainText, ref IntPtr pdwBufferSize, IntPtr lpBuffer); [DllImport("pdh.dll", CharSet = CharSet.Unicode)] private static extern uint PdhGetCounterTimeBase(IntPtr hCounter, out UInt64 pTimeBase); diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs index 5397731bca..effcf9df6e 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs @@ -2351,82 +2351,82 @@ namespace Microsoft.PowerShell.Commands private void SetStartupInfo(ProcessStartInfo startinfo, ref ProcessNativeMethods.STARTUPINFO lpStartupInfo, ref int creationFlags) { - // RedirectionStandardInput - if (_redirectstandardinput != null) - { - startinfo.RedirectStandardInput = true; - _redirectstandardinput = ResolveFilePath(_redirectstandardinput); - lpStartupInfo.hStdInput = GetSafeFileHandleForRedirection(_redirectstandardinput, ProcessNativeMethods.OPEN_EXISTING); - } - else - { - lpStartupInfo.hStdInput = new SafeFileHandle(ProcessNativeMethods.GetStdHandle(-10), false); - } + // RedirectionStandardInput + if (_redirectstandardinput != null) + { + startinfo.RedirectStandardInput = true; + _redirectstandardinput = ResolveFilePath(_redirectstandardinput); + lpStartupInfo.hStdInput = GetSafeFileHandleForRedirection(_redirectstandardinput, ProcessNativeMethods.OPEN_EXISTING); + } + else + { + lpStartupInfo.hStdInput = new SafeFileHandle(ProcessNativeMethods.GetStdHandle(-10), false); + } - // RedirectionStandardOutput - if (_redirectstandardoutput != null) - { - startinfo.RedirectStandardOutput = true; - _redirectstandardoutput = ResolveFilePath(_redirectstandardoutput); - lpStartupInfo.hStdOutput = GetSafeFileHandleForRedirection(_redirectstandardoutput, ProcessNativeMethods.CREATE_ALWAYS); - } - else - { - lpStartupInfo.hStdOutput = new SafeFileHandle(ProcessNativeMethods.GetStdHandle(-11), false); - } + // RedirectionStandardOutput + if (_redirectstandardoutput != null) + { + startinfo.RedirectStandardOutput = true; + _redirectstandardoutput = ResolveFilePath(_redirectstandardoutput); + lpStartupInfo.hStdOutput = GetSafeFileHandleForRedirection(_redirectstandardoutput, ProcessNativeMethods.CREATE_ALWAYS); + } + else + { + lpStartupInfo.hStdOutput = new SafeFileHandle(ProcessNativeMethods.GetStdHandle(-11), false); + } - // RedirectionStandardError - if (_redirectstandarderror != null) + // RedirectionStandardError + if (_redirectstandarderror != null) + { + startinfo.RedirectStandardError = true; + _redirectstandarderror = ResolveFilePath(_redirectstandarderror); + lpStartupInfo.hStdError = GetSafeFileHandleForRedirection(_redirectstandarderror, ProcessNativeMethods.CREATE_ALWAYS); + } + else + { + lpStartupInfo.hStdError = new SafeFileHandle(ProcessNativeMethods.GetStdHandle(-12), false); + } + + // STARTF_USESTDHANDLES + lpStartupInfo.dwFlags = 0x100; + + if (startinfo.CreateNoWindow) + { + // No new window: Inherit the parent process's console window + creationFlags = 0x00000000; + } + else + { + // CREATE_NEW_CONSOLE + creationFlags |= 0x00000010; + + // STARTF_USESHOWWINDOW + lpStartupInfo.dwFlags |= 0x00000001; + + // On headless SKUs like NanoServer and IoT, window style can only be the default value 'Normal'. + switch (startinfo.WindowStyle) { - startinfo.RedirectStandardError = true; - _redirectstandarderror = ResolveFilePath(_redirectstandarderror); - lpStartupInfo.hStdError = GetSafeFileHandleForRedirection(_redirectstandarderror, ProcessNativeMethods.CREATE_ALWAYS); - } - else - { - lpStartupInfo.hStdError = new SafeFileHandle(ProcessNativeMethods.GetStdHandle(-12), false); + case ProcessWindowStyle.Normal: + // SW_SHOWNORMAL + lpStartupInfo.wShowWindow = 1; + break; + case ProcessWindowStyle.Minimized: + // SW_SHOWMINIMIZED + lpStartupInfo.wShowWindow = 2; + break; + case ProcessWindowStyle.Maximized: + // SW_SHOWMAXIMIZED + lpStartupInfo.wShowWindow = 3; + break; + case ProcessWindowStyle.Hidden: + // SW_HIDE + lpStartupInfo.wShowWindow = 0; + break; } + } - // STARTF_USESTDHANDLES - lpStartupInfo.dwFlags = 0x100; - - if (startinfo.CreateNoWindow) - { - // No new window: Inherit the parent process's console window - creationFlags = 0x00000000; - } - else - { - // CREATE_NEW_CONSOLE - creationFlags |= 0x00000010; - - // STARTF_USESHOWWINDOW - lpStartupInfo.dwFlags |= 0x00000001; - - // On headless SKUs like NanoServer and IoT, window style can only be the default value 'Normal'. - switch (startinfo.WindowStyle) - { - case ProcessWindowStyle.Normal: - // SW_SHOWNORMAL - lpStartupInfo.wShowWindow = 1; - break; - case ProcessWindowStyle.Minimized: - // SW_SHOWMINIMIZED - lpStartupInfo.wShowWindow = 2; - break; - case ProcessWindowStyle.Maximized: - // SW_SHOWMAXIMIZED - lpStartupInfo.wShowWindow = 3; - break; - case ProcessWindowStyle.Hidden: - // SW_HIDE - lpStartupInfo.wShowWindow = 0; - break; - } - } - - // Create the new process suspended so we have a chance to get a corresponding Process object in case it terminates quickly. - creationFlags |= 0x00000004; + // Create the new process suspended so we have a chance to get a corresponding Process object in case it terminates quickly. + creationFlags |= 0x00000004; } /// diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ManagedEntrance.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ManagedEntrance.cs index d0ee497307..6dbc21ab24 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ManagedEntrance.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ManagedEntrance.cs @@ -33,7 +33,7 @@ namespace Microsoft.PowerShell /// Length of the passed in argument array. /// [Obsolete("Callers should now use UnmanagedPSEntry.Start(string[], int)", error: true)] - public static int Start(string consoleFilePath, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 2)]string[] args, int argc) + public static int Start(string consoleFilePath, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 2)] string[] args, int argc) { return Start(args, argc); } @@ -47,7 +47,7 @@ namespace Microsoft.PowerShell /// /// Length of the passed in argument array. /// - public static int Start([MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 1)]string[] args, int argc) + public static int Start([MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 1)] string[] args, int argc) { if (args == null) { diff --git a/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/UnsafeNativeMethods.cs b/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/UnsafeNativeMethods.cs index 5da8809897..abc1bb0333 100644 --- a/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/UnsafeNativeMethods.cs +++ b/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/UnsafeNativeMethods.cs @@ -121,9 +121,9 @@ namespace System.Diagnostics.Eventing [SecurityCritical] internal static extern unsafe uint EventRegister( [In] ref Guid providerId, - [In]EtwEnableCallback enableCallback, - [In]void* callbackContext, - [In][Out]ref long registrationHandle + [In] EtwEnableCallback enableCallback, + [In] void* callbackContext, + [In][Out] ref long registrationHandle ); [DllImport(EventProviderDllName, ExactSpelling = true, EntryPoint = "EventUnregister", CharSet = System.Runtime.InteropServices.CharSet.Unicode)] @@ -553,8 +553,8 @@ namespace System.Diagnostics.Eventing [SecurityCritical] internal static extern EventLogHandle EvtQuery( EventLogHandle session, - [MarshalAs(UnmanagedType.LPWStr)]string path, - [MarshalAs(UnmanagedType.LPWStr)]string query, + [MarshalAs(UnmanagedType.LPWStr)] string path, + [MarshalAs(UnmanagedType.LPWStr)] string query, int flags); // SEEK @@ -566,7 +566,7 @@ namespace System.Diagnostics.Eventing long position, EventLogHandle bookmark, int timeout, - [MarshalAs(UnmanagedType.I4)]EvtSeekFlags flags + [MarshalAs(UnmanagedType.I4)] EvtSeekFlags flags ); [DllImport(WEVTAPI, CallingConvention = CallingConvention.Winapi, SetLastError = true)] @@ -603,7 +603,7 @@ namespace System.Diagnostics.Eventing internal static extern bool EvtGetEventInfo( EventLogHandle eventHandle, // int propertyId - [MarshalAs(UnmanagedType.I4)]EvtEventPropertyId propertyId, + [MarshalAs(UnmanagedType.I4)] EvtEventPropertyId propertyId, int bufferSize, IntPtr bufferPtr, out int bufferUsed @@ -614,7 +614,7 @@ namespace System.Diagnostics.Eventing [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool EvtGetQueryInfo( EventLogHandle queryHandle, - [MarshalAs(UnmanagedType.I4)]EvtQueryPropertyId propertyId, + [MarshalAs(UnmanagedType.I4)] EvtQueryPropertyId propertyId, int bufferSize, IntPtr buffer, ref int bufferRequired @@ -686,7 +686,7 @@ namespace System.Diagnostics.Eventing [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool EvtGetEventMetadataProperty( EventLogHandle eventMetadata, - [MarshalAs(UnmanagedType.I4)] EvtEventMetadataPropertyId propertyId, + [MarshalAs(UnmanagedType.I4)] EvtEventMetadataPropertyId propertyId, int flags, int eventMetadataPropertyBufferSize, IntPtr eventMetadataPropertyBuffer, @@ -708,7 +708,7 @@ namespace System.Diagnostics.Eventing EventLogHandle channelEnum, int channelPathBufferSize, // StringBuilder channelPathBuffer, - [Out, MarshalAs(UnmanagedType.LPWStr)]StringBuilder channelPathBuffer, + [Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder channelPathBuffer, out int channelPathBufferUsed ); @@ -725,7 +725,7 @@ namespace System.Diagnostics.Eventing internal static extern bool EvtNextPublisherId( EventLogHandle publisherEnum, int publisherIdBufferSize, - [Out, MarshalAs(UnmanagedType.LPWStr)]StringBuilder publisherIdBuffer, + [Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder publisherIdBuffer, out int publisherIdBufferUsed ); @@ -733,7 +733,7 @@ namespace System.Diagnostics.Eventing [SecurityCritical] internal static extern EventLogHandle EvtOpenChannelConfig( EventLogHandle session, - [MarshalAs(UnmanagedType.LPWStr)]String channelPath, + [MarshalAs(UnmanagedType.LPWStr)] String channelPath, int flags ); @@ -750,7 +750,7 @@ namespace System.Diagnostics.Eventing [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool EvtSetChannelConfigProperty( EventLogHandle channelConfig, - [MarshalAs(UnmanagedType.I4)]EvtChannelConfigPropertyId propertyId, + [MarshalAs(UnmanagedType.I4)] EvtChannelConfigPropertyId propertyId, int flags, ref EvtVariant propertyValue ); @@ -760,7 +760,7 @@ namespace System.Diagnostics.Eventing [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool EvtGetChannelConfigProperty( EventLogHandle channelConfig, - [MarshalAs(UnmanagedType.I4)]EvtChannelConfigPropertyId propertyId, + [MarshalAs(UnmanagedType.I4)] EvtChannelConfigPropertyId propertyId, int flags, int propertyValueBufferSize, IntPtr propertyValueBuffer, @@ -773,7 +773,7 @@ namespace System.Diagnostics.Eventing internal static extern EventLogHandle EvtOpenLog( EventLogHandle session, [MarshalAs(UnmanagedType.LPWStr)] string path, - [MarshalAs(UnmanagedType.I4)]PathType flags + [MarshalAs(UnmanagedType.I4)] PathType flags ); [DllImport(WEVTAPI, CharSet = CharSet.Unicode, SetLastError = true)] @@ -781,7 +781,7 @@ namespace System.Diagnostics.Eventing [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool EvtGetLogInfo( EventLogHandle log, - [MarshalAs(UnmanagedType.I4)]EvtLogPropertyId propertyId, + [MarshalAs(UnmanagedType.I4)] EvtLogPropertyId propertyId, int propertyValueBufferSize, IntPtr propertyValueBuffer, out int propertyValueBufferUsed @@ -793,9 +793,9 @@ namespace System.Diagnostics.Eventing [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool EvtExportLog( EventLogHandle session, - [MarshalAs(UnmanagedType.LPWStr)]string channelPath, - [MarshalAs(UnmanagedType.LPWStr)]string query, - [MarshalAs(UnmanagedType.LPWStr)]string targetFilePath, + [MarshalAs(UnmanagedType.LPWStr)] string channelPath, + [MarshalAs(UnmanagedType.LPWStr)] string query, + [MarshalAs(UnmanagedType.LPWStr)] string targetFilePath, int flags ); @@ -804,7 +804,7 @@ namespace System.Diagnostics.Eventing [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool EvtArchiveExportedLog( EventLogHandle session, - [MarshalAs(UnmanagedType.LPWStr)]string logFilePath, + [MarshalAs(UnmanagedType.LPWStr)] string logFilePath, int locale, int flags ); @@ -814,8 +814,8 @@ namespace System.Diagnostics.Eventing [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool EvtClearLog( EventLogHandle session, - [MarshalAs(UnmanagedType.LPWStr)]string channelPath, - [MarshalAs(UnmanagedType.LPWStr)]string targetFilePath, + [MarshalAs(UnmanagedType.LPWStr)] string channelPath, + [MarshalAs(UnmanagedType.LPWStr)] string targetFilePath, int flags ); @@ -826,7 +826,7 @@ namespace System.Diagnostics.Eventing Int32 valuePathsCount, [MarshalAs(UnmanagedType.LPArray,ArraySubType = UnmanagedType.LPWStr)] string[] valuePaths, - [MarshalAs(UnmanagedType.I4)]EvtRenderContextFlags flags + [MarshalAs(UnmanagedType.I4)] EvtRenderContextFlags flags ); [DllImport(WEVTAPI, CallingConvention = CallingConvention.Winapi, SetLastError = true)] @@ -837,7 +837,7 @@ namespace System.Diagnostics.Eventing EventLogHandle eventHandle, EvtRenderFlags flags, int buffSize, - [Out, MarshalAs(UnmanagedType.LPWStr)]StringBuilder buffer, + [Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder buffer, out int buffUsed, out int propCount ); @@ -877,9 +877,9 @@ namespace System.Diagnostics.Eventing uint messageId, int valueCount, EvtStringVariant[] values, - [MarshalAs(UnmanagedType.I4)]EvtFormatMessageFlags flags, + [MarshalAs(UnmanagedType.I4)] EvtFormatMessageFlags flags, int bufferSize, - [Out, MarshalAs(UnmanagedType.LPWStr)]StringBuilder buffer, + [Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder buffer, out int bufferUsed ); @@ -892,7 +892,7 @@ namespace System.Diagnostics.Eventing uint messageId, int valueCount, IntPtr values, - [MarshalAs(UnmanagedType.I4)]EvtFormatMessageFlags flags, + [MarshalAs(UnmanagedType.I4)] EvtFormatMessageFlags flags, int bufferSize, IntPtr buffer, out int bufferUsed @@ -902,7 +902,7 @@ namespace System.Diagnostics.Eventing [DllImport(WEVTAPI, CharSet = CharSet.Unicode, SetLastError = true)] [SecurityCritical] internal static extern EventLogHandle EvtOpenSession( - [MarshalAs(UnmanagedType.I4)]EvtLoginClass loginClass, + [MarshalAs(UnmanagedType.I4)] EvtLoginClass loginClass, ref EvtRpcLogin login, int timeout, int flags diff --git a/src/System.Management.Automation/CoreCLR/CorePsAssemblyLoadContext.cs b/src/System.Management.Automation/CoreCLR/CorePsAssemblyLoadContext.cs index aa1e8d40ce..12f575b517 100644 --- a/src/System.Management.Automation/CoreCLR/CorePsAssemblyLoadContext.cs +++ b/src/System.Management.Automation/CoreCLR/CorePsAssemblyLoadContext.cs @@ -580,7 +580,7 @@ namespace System.Management.Automation /// Base directory paths that are separated by semicolon ';'. /// They will be the default paths to probe assemblies. /// - public static void SetPowerShellAssemblyLoadContext([MarshalAs(UnmanagedType.LPWStr)]string basePaths) + public static void SetPowerShellAssemblyLoadContext([MarshalAs(UnmanagedType.LPWStr)] string basePaths) { if (string.IsNullOrEmpty(basePaths)) throw new ArgumentNullException(nameof(basePaths)); diff --git a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs index df416a3dc2..981d6bfb08 100644 --- a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs +++ b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs @@ -1008,11 +1008,11 @@ namespace System.Management.Automation internal static extern int GetPPid(int pid); [DllImport(psLib, CharSet = CharSet.Ansi, SetLastError = true)] - internal static extern int GetLinkCount([MarshalAs(UnmanagedType.LPStr)]string filePath, out int linkCount); + internal static extern int GetLinkCount([MarshalAs(UnmanagedType.LPStr)] string filePath, out int linkCount); [DllImport(psLib, CharSet = CharSet.Ansi, SetLastError = true)] [return: MarshalAs(UnmanagedType.I1)] - internal static extern bool IsExecutable([MarshalAs(UnmanagedType.LPStr)]string filePath); + internal static extern bool IsExecutable([MarshalAs(UnmanagedType.LPStr)] string filePath); [DllImport(psLib, CharSet = CharSet.Ansi)] internal static extern uint GetCurrentThreadId(); @@ -1069,16 +1069,16 @@ namespace System.Management.Automation internal static extern unsafe int SetDate(UnixTm* tm); [DllImport(psLib, CharSet = CharSet.Ansi, SetLastError = true)] - internal static extern int CreateSymLink([MarshalAs(UnmanagedType.LPStr)]string filePath, - [MarshalAs(UnmanagedType.LPStr)]string target); + internal static extern int CreateSymLink([MarshalAs(UnmanagedType.LPStr)] string filePath, + [MarshalAs(UnmanagedType.LPStr)] string target); [DllImport(psLib, CharSet = CharSet.Ansi, SetLastError = true)] - internal static extern int CreateHardLink([MarshalAs(UnmanagedType.LPStr)]string filePath, - [MarshalAs(UnmanagedType.LPStr)]string target); + internal static extern int CreateHardLink([MarshalAs(UnmanagedType.LPStr)] string filePath, + [MarshalAs(UnmanagedType.LPStr)] string target); [DllImport(psLib, CharSet = CharSet.Ansi, SetLastError = true)] [return: MarshalAs(UnmanagedType.LPStr)] - internal static extern string FollowSymLink([MarshalAs(UnmanagedType.LPStr)]string filePath); + internal static extern string FollowSymLink([MarshalAs(UnmanagedType.LPStr)] string filePath); [DllImport(psLib, CharSet = CharSet.Ansi, SetLastError = true)] [return: MarshalAs(UnmanagedType.LPStr)] @@ -1086,11 +1086,11 @@ namespace System.Management.Automation [DllImport(psLib, CharSet = CharSet.Ansi, SetLastError = true)] [return: MarshalAs(UnmanagedType.I1)] - internal static extern bool IsSameFileSystemItem([MarshalAs(UnmanagedType.LPStr)]string filePathOne, - [MarshalAs(UnmanagedType.LPStr)]string filePathTwo); + internal static extern bool IsSameFileSystemItem([MarshalAs(UnmanagedType.LPStr)] string filePathOne, + [MarshalAs(UnmanagedType.LPStr)] string filePathTwo); [DllImport(psLib, CharSet = CharSet.Ansi, SetLastError = true)] - internal static extern int GetInodeData([MarshalAs(UnmanagedType.LPStr)]string path, + internal static extern int GetInodeData([MarshalAs(UnmanagedType.LPStr)] string path, out UInt64 device, out UInt64 inode); /// diff --git a/src/System.Management.Automation/engine/COM/ComDispatch.cs b/src/System.Management.Automation/engine/COM/ComDispatch.cs index 9199ef9f48..3f6afa6440 100644 --- a/src/System.Management.Automation/engine/COM/ComDispatch.cs +++ b/src/System.Management.Automation/engine/COM/ComDispatch.cs @@ -33,7 +33,7 @@ namespace System.Management.Automation [MarshalAs(UnmanagedType.LPStruct)] Guid iid, int lcid, COM.INVOKEKIND wFlags, - [In, Out] [MarshalAs(UnmanagedType.LPArray)] COM.DISPPARAMS[] paramArray, + [In, Out][MarshalAs(UnmanagedType.LPArray)] COM.DISPPARAMS[] paramArray, out object pVarResult, out ComInvoker.EXCEPINFO pExcepInfo, out uint puArgErr); diff --git a/src/System.Management.Automation/engine/ComInterop/VariantArray.cs b/src/System.Management.Automation/engine/ComInterop/VariantArray.cs index 83ea62e51f..a196eb9607 100644 --- a/src/System.Management.Automation/engine/ComInterop/VariantArray.cs +++ b/src/System.Management.Automation/engine/ComInterop/VariantArray.cs @@ -74,7 +74,7 @@ namespace System.Management.Automation.ComInterop // See if we can find an existing type foreach (Type t in s_generatedTypes) { - int arity = int.Parse(t.Name.AsSpan("VariantArray".Length), NumberStyles.Integer, CultureInfo.InvariantCulture); + int arity = int.Parse(t.Name.AsSpan("VariantArray".Length), NumberStyles.Integer, CultureInfo.InvariantCulture); if (size == arity) { return t; diff --git a/src/System.Management.Automation/engine/Modules/ImportModuleCommand.cs b/src/System.Management.Automation/engine/Modules/ImportModuleCommand.cs index f6641930bf..4c5f14cadf 100644 --- a/src/System.Management.Automation/engine/Modules/ImportModuleCommand.cs +++ b/src/System.Management.Automation/engine/Modules/ImportModuleCommand.cs @@ -2024,7 +2024,7 @@ namespace Microsoft.PowerShell.Commands // perform necessary preparations if module has to be imported with NoClobber mode if (filteredModuleNames != null) { - foreach(string moduleName in filteredModuleNames) + foreach (string moduleName in filteredModuleNames) { PrepareNoClobberWinCompatModuleImport(moduleName, null, ref importModuleOptions); } @@ -2032,7 +2032,7 @@ namespace Microsoft.PowerShell.Commands if (filteredModuleFullyQualifiedNames != null) { - foreach(var moduleSpec in filteredModuleFullyQualifiedNames) + foreach (var moduleSpec in filteredModuleFullyQualifiedNames) { PrepareNoClobberWinCompatModuleImport(null, moduleSpec, ref importModuleOptions); } diff --git a/src/System.Management.Automation/engine/ReflectionParameterBinder.cs b/src/System.Management.Automation/engine/ReflectionParameterBinder.cs index 3e5dcab250..ee0562f5b8 100644 --- a/src/System.Management.Automation/engine/ReflectionParameterBinder.cs +++ b/src/System.Management.Automation/engine/ReflectionParameterBinder.cs @@ -190,17 +190,20 @@ namespace System.Management.Automation s_setterMethods.TryAdd(Tuple.Create(typeof(GetModuleCommand), "FullyQualifiedName"), (o, v) => ((GetModuleCommand)o).FullyQualifiedName = (ModuleSpecification[])v); s_setterMethods.TryAdd(Tuple.Create(typeof(CommonParameters), "ErrorAction"), - (o, v) => { + (o, v) => + { v ??= LanguagePrimitives.ThrowInvalidCastException(null, typeof(ActionPreference)); ((CommonParameters)o).ErrorAction = (ActionPreference)v; }); s_setterMethods.TryAdd(Tuple.Create(typeof(CommonParameters), "WarningAction"), - (o, v) => { + (o, v) => + { v ??= LanguagePrimitives.ThrowInvalidCastException(null, typeof(ActionPreference)); ((CommonParameters)o).WarningAction = (ActionPreference)v; }); s_setterMethods.TryAdd(Tuple.Create(typeof(CommonParameters), "InformationAction"), - (o, v) => { + (o, v) => + { v ??= LanguagePrimitives.ThrowInvalidCastException(null, typeof(ActionPreference)); ((CommonParameters)o).InformationAction = (ActionPreference)v; }); diff --git a/src/System.Management.Automation/engine/Subsystem/CommandPrediction/CommandPrediction.cs b/src/System.Management.Automation/engine/Subsystem/CommandPrediction/CommandPrediction.cs index f77072ea37..30deb1b309 100644 --- a/src/System.Management.Automation/engine/Subsystem/CommandPrediction/CommandPrediction.cs +++ b/src/System.Management.Automation/engine/Subsystem/CommandPrediction/CommandPrediction.cs @@ -82,7 +82,8 @@ namespace System.Management.Automation.Subsystem ICommandPredictor predictor = predictors[i]; tasks[i] = Task.Factory.StartNew( - state => { + state => + { var predictor = (ICommandPredictor)state!; List? texts = predictor.GetSuggestion(context, cancellationSource.Token); return texts?.Count > 0 ? new PredictionResult(predictor.Id, predictor.Name, texts) : null; diff --git a/src/System.Management.Automation/engine/remoting/fanin/WSManNativeAPI.cs b/src/System.Management.Automation/engine/remoting/fanin/WSManNativeAPI.cs index b46c13b5ea..0820049feb 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/WSManNativeAPI.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/WSManNativeAPI.cs @@ -2357,7 +2357,7 @@ namespace System.Management.Automation.Remoting.Client /// [DllImport(WSManNativeApi.WSManClientApiDll, SetLastError = false, CharSet = CharSet.Unicode)] internal static extern int WSManInitialize(int flags, - [In, Out] ref IntPtr wsManAPIHandle); + [In, Out] ref IntPtr wsManAPIHandle); /// /// This API deinitializes the Winrm client stack; all operations will @@ -2390,11 +2390,11 @@ namespace System.Management.Automation.Remoting.Client /// [DllImport(WSManNativeApi.WSManClientApiDll, SetLastError = false, CharSet = CharSet.Unicode)] internal static extern int WSManCreateSession(IntPtr wsManAPIHandle, - [MarshalAs(UnmanagedType.LPWStr)]string connection, + [MarshalAs(UnmanagedType.LPWStr)] string connection, int flags, IntPtr authenticationCredentials, IntPtr proxyInfo, - [In, Out] ref IntPtr wsManSessionHandle); + [In, Out] ref IntPtr wsManSessionHandle); /// /// Frees memory of session and closes all related operations before returning; @@ -2553,13 +2553,13 @@ namespace System.Management.Automation.Remoting.Client [DllImport(WSManNativeApi.WSManClientApiDll, EntryPoint = "WSManCreateShellEx", SetLastError = false, CharSet = CharSet.Unicode)] private static extern void WSManCreateShellExInternal(IntPtr wsManSessionHandle, int flags, - [MarshalAs(UnmanagedType.LPWStr)]string resourceUri, - [MarshalAs(UnmanagedType.LPWStr)]string shellId, + [MarshalAs(UnmanagedType.LPWStr)] string resourceUri, + [MarshalAs(UnmanagedType.LPWStr)] string shellId, IntPtr startupInfo, IntPtr optionSet, IntPtr openContent, IntPtr asyncCallback, - [In, Out] ref IntPtr shellOperationHandle); + [In, Out] ref IntPtr shellOperationHandle); /// /// @@ -2574,12 +2574,12 @@ namespace System.Management.Automation.Remoting.Client [DllImport(WSManNativeApi.WSManClientApiDll, EntryPoint = "WSManConnectShell", SetLastError = false, CharSet = CharSet.Unicode)] internal static extern void WSManConnectShellEx(IntPtr wsManSessionHandle, int flags, - [MarshalAs(UnmanagedType.LPWStr)]string resourceUri, - [MarshalAs(UnmanagedType.LPWStr)]string shellId, + [MarshalAs(UnmanagedType.LPWStr)] string resourceUri, + [MarshalAs(UnmanagedType.LPWStr)] string shellId, IntPtr optionSet, IntPtr connectXml, IntPtr asyncCallback, - [In, Out] ref IntPtr shellOperationHandle); + [In, Out] ref IntPtr shellOperationHandle); /// /// @@ -2685,7 +2685,7 @@ namespace System.Management.Automation.Remoting.Client int flags, IntPtr desiredStreamSet, IntPtr asyncCallback, - [In, Out] ref IntPtr receiveOperationHandle); + [In, Out] ref IntPtr receiveOperationHandle); /// /// Send data to the remote end. @@ -2726,7 +2726,7 @@ namespace System.Management.Automation.Remoting.Client IntPtr streamData, bool endOfStream, IntPtr asyncCallback, - [In, Out] ref IntPtr sendOperationHandle); + [In, Out] ref IntPtr sendOperationHandle); /// /// Closes a shell or a command; if the callback associated with the operation diff --git a/src/System.Management.Automation/engine/remoting/fanin/WSManPlugin.cs b/src/System.Management.Automation/engine/remoting/fanin/WSManPlugin.cs index f408b45d63..d4a8e027b7 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/WSManPlugin.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/WSManPlugin.cs @@ -306,10 +306,10 @@ namespace System.Management.Automation.Remoting PSOpcode.Connect, PSTask.None, PSKeyword.ManagedPlugin | PSKeyword.UseAlwaysAnalytic, requestDetails.ToString(), senderInfo.UserInfo.Identity.Name, requestDetails.resourceUri); - ServerRemoteSession remoteShellSession = ServerRemoteSession.CreateServerRemoteSession(senderInfo, - requestDetails.resourceUri, - extraInfo, - serverTransportMgr); + ServerRemoteSession remoteShellSession = ServerRemoteSession.CreateServerRemoteSession(senderInfo, + requestDetails.resourceUri, + extraInfo, + serverTransportMgr); if (remoteShellSession == null) { diff --git a/src/System.Management.Automation/namespaces/FileSystemProvider.cs b/src/System.Management.Automation/namespaces/FileSystemProvider.cs index be4b95dc93..cd8b245399 100644 --- a/src/System.Management.Automation/namespaces/FileSystemProvider.cs +++ b/src/System.Management.Automation/namespaces/FileSystemProvider.cs @@ -7699,7 +7699,7 @@ namespace Microsoft.PowerShell.Commands /// public class FileSystemContentReaderDynamicParameters : FileSystemContentDynamicParametersBase { - internal FileSystemContentReaderDynamicParameters(FileSystemProvider provider) : base (provider) { } + internal FileSystemContentReaderDynamicParameters(FileSystemProvider provider) : base(provider) { } /// /// Gets or sets the delimiter to use when reading the file. Custom delimiters diff --git a/src/System.Management.Automation/namespaces/RegistryProvider.cs b/src/System.Management.Automation/namespaces/RegistryProvider.cs index bac9796e0f..b841557372 100644 --- a/src/System.Management.Automation/namespaces/RegistryProvider.cs +++ b/src/System.Management.Automation/namespaces/RegistryProvider.cs @@ -3834,7 +3834,9 @@ namespace Microsoft.PowerShell.Commands { value = 0; } - } break; + } + + break; case RegistryValueKind.ExpandString: value = (value != null) @@ -3871,7 +3873,9 @@ namespace Microsoft.PowerShell.Commands { value = 0; } - } break; + } + + break; case RegistryValueKind.String: value = (value != null) diff --git a/src/System.Management.Automation/security/SecureStringHelper.cs b/src/System.Management.Automation/security/SecureStringHelper.cs index e6180dc39b..4c0782e55d 100644 --- a/src/System.Management.Automation/security/SecureStringHelper.cs +++ b/src/System.Management.Automation/security/SecureStringHelper.cs @@ -617,23 +617,23 @@ namespace Microsoft.PowerShell [DllImport("CRYPT32.dll", CharSet = CharSet.Unicode, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool CryptProtectData( - [In] IntPtr pDataIn, - [In] string szDataDescr, - [In] IntPtr pOptionalEntropy, - [In] IntPtr pvReserved, - [In] IntPtr pPromptStruct, - [In] uint dwFlags, + [In] IntPtr pDataIn, + [In] string szDataDescr, + [In] IntPtr pOptionalEntropy, + [In] IntPtr pvReserved, + [In] IntPtr pPromptStruct, + [In] uint dwFlags, [In, Out] IntPtr pDataBlob); [DllImport("CRYPT32.dll", CharSet = CharSet.Unicode, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool CryptUnprotectData( - [In] IntPtr pDataIn, - [In] IntPtr ppszDataDescr, - [In] IntPtr pOptionalEntropy, - [In] IntPtr pvReserved, - [In] IntPtr pPromptStruct, - [In] uint dwFlags, + [In] IntPtr pDataIn, + [In] IntPtr ppszDataDescr, + [In] IntPtr pOptionalEntropy, + [In] IntPtr pvReserved, + [In] IntPtr pPromptStruct, + [In] uint dwFlags, [In, Out] IntPtr pDataBlob); [DllImport("ntdll.dll", EntryPoint = "RtlZeroMemory", SetLastError = true)] diff --git a/src/System.Management.Automation/security/SecurityManager.cs b/src/System.Management.Automation/security/SecurityManager.cs index f6ae0fdf1f..035ce85997 100644 --- a/src/System.Management.Automation/security/SecurityManager.cs +++ b/src/System.Management.Automation/security/SecurityManager.cs @@ -383,7 +383,9 @@ namespace Microsoft.PowerShell { TrustPublisher(signature); policyCheckPassed = true; - } break; + } + + break; case RunPromptDecision.DoNotRun: policyCheckPassed = false; reasonMessage = StringUtil.Format(Authenticode.Reason_DoNotRun, path); @@ -395,7 +397,9 @@ namespace Microsoft.PowerShell reasonMessage = StringUtil.Format(Authenticode.Reason_NeverRun, path); reason = new UnauthorizedAccessException(reasonMessage); policyCheckPassed = false; - } break; + } + + break; } return policyCheckPassed; diff --git a/src/System.Management.Automation/security/SecuritySupport.cs b/src/System.Management.Automation/security/SecuritySupport.cs index 90d4a71d73..4303075d8e 100644 --- a/src/System.Management.Automation/security/SecuritySupport.cs +++ b/src/System.Management.Automation/security/SecuritySupport.cs @@ -1605,7 +1605,7 @@ namespace System.Management.Automation [DefaultDllImportSearchPathsAttribute(DllImportSearchPath.System32)] [DllImportAttribute("amsi.dll", EntryPoint = "AmsiInitialize", CallingConvention = CallingConvention.StdCall)] internal static extern int AmsiInitialize( - [InAttribute()] [MarshalAsAttribute(UnmanagedType.LPWStr)] string appName, ref System.IntPtr amsiContext); + [InAttribute()][MarshalAsAttribute(UnmanagedType.LPWStr)] string appName, ref System.IntPtr amsiContext); /// Return Type: void ///amsiContext: HAMSICONTEXT->HAMSICONTEXT__* @@ -1638,7 +1638,7 @@ namespace System.Management.Automation [DllImportAttribute("amsi.dll", EntryPoint = "AmsiScanBuffer", CallingConvention = CallingConvention.StdCall)] internal static extern int AmsiScanBuffer( System.IntPtr amsiContext, System.IntPtr buffer, uint length, - [InAttribute()] [MarshalAsAttribute(UnmanagedType.LPWStr)] string contentName, System.IntPtr amsiSession, ref AMSI_RESULT result); + [InAttribute()][MarshalAsAttribute(UnmanagedType.LPWStr)] string contentName, System.IntPtr amsiSession, ref AMSI_RESULT result); /// Return Type: HRESULT->LONG->int ///amsiContext: HAMSICONTEXT->HAMSICONTEXT__* @@ -1649,8 +1649,8 @@ namespace System.Management.Automation [DefaultDllImportSearchPathsAttribute(DllImportSearchPath.System32)] [DllImportAttribute("amsi.dll", EntryPoint = "AmsiScanString", CallingConvention = CallingConvention.StdCall)] internal static extern int AmsiScanString( - System.IntPtr amsiContext, [InAttribute()] [MarshalAsAttribute(UnmanagedType.LPWStr)] string @string, - [InAttribute()] [MarshalAsAttribute(UnmanagedType.LPWStr)] string contentName, System.IntPtr amsiSession, ref AMSI_RESULT result); + System.IntPtr amsiContext, [InAttribute()][MarshalAsAttribute(UnmanagedType.LPWStr)] string @string, + [InAttribute()][MarshalAsAttribute(UnmanagedType.LPWStr)] string contentName, System.IntPtr amsiSession, ref AMSI_RESULT result); } } } diff --git a/src/System.Management.Automation/security/nativeMethods.cs b/src/System.Management.Automation/security/nativeMethods.cs index a48c430f23..e6ca212c27 100644 --- a/src/System.Management.Automation/security/nativeMethods.cs +++ b/src/System.Management.Automation/security/nativeMethods.cs @@ -1151,7 +1151,7 @@ namespace System.Management.Automation.Security ///ppCertContext: void** ///phWVTStateData: HANDLE* [DllImportAttribute("wintrust.dll", EntryPoint = "WTGetSignatureInfo", CallingConvention = CallingConvention.StdCall)] - internal static extern int WTGetSignatureInfo([InAttribute()] [MarshalAsAttribute(UnmanagedType.LPWStr)] string pszFile, [InAttribute()] System.IntPtr hFile, SIGNATURE_INFO_FLAGS sigInfoFlags, ref SIGNATURE_INFO psiginfo, ref System.IntPtr ppCertContext, ref System.IntPtr phWVTStateData); + internal static extern int WTGetSignatureInfo([InAttribute()][MarshalAsAttribute(UnmanagedType.LPWStr)] string pszFile, [InAttribute()] System.IntPtr hFile, SIGNATURE_INFO_FLAGS sigInfoFlags, ref SIGNATURE_INFO psiginfo, ref System.IntPtr ppCertContext, ref System.IntPtr phWVTStateData); internal static void FreeWVTStateData(System.IntPtr phWVTStateData) { diff --git a/src/System.Management.Automation/utils/CryptoUtils.cs b/src/System.Management.Automation/utils/CryptoUtils.cs index 43e04754fc..b8b5533a04 100644 --- a/src/System.Management.Automation/utils/CryptoUtils.cs +++ b/src/System.Management.Automation/utils/CryptoUtils.cs @@ -64,7 +64,7 @@ namespace System.Management.Automation.Internal private static int ToInt32LE(byte[] bytes, int offset) { - return (bytes[offset + 3] << 24) | (bytes[offset + 2] << 16) | (bytes[offset + 1 ] << 8) | bytes[offset]; + return (bytes[offset + 3] << 24) | (bytes[offset + 2] << 16) | (bytes[offset + 1] << 8) | bytes[offset]; } private static uint ToUInt32LE(byte[] bytes, int offset) @@ -140,7 +140,7 @@ namespace System.Management.Automation.Internal try { - if ((blob[offset] != PUBLICKEYBLOB) || // PUBLICKEYBLOB (0x06) + if ((blob[offset] != PUBLICKEYBLOB) || // PUBLICKEYBLOB (0x06) (blob[offset + 1] != CUR_BLOB_VERSION) || // Version (0x02) (blob[offset + 2] != 0x00) || // Reserved (word) (blob[offset + 3] != 0x00) ||