From 8eda0df29ec046c48d2dae39cc47fceaff7a83b7 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Tue, 19 Jul 2016 12:27:34 -0700 Subject: [PATCH] Remove CommandLineParameterBinderNativeMethods This was dead code. PreParseCommandLine was called only when tracing was enabled, which meant that the tracing itself was useless, as it was not tracing what the actual code was doing. I believe the intention of this tracing was to "guess" how the native commands on Windows *might* parse their command-line arguments, but the traced result was not guaranteed to be accurate. Since we cannot provide accurate tracing, the tracer was removed in its entirety. The PreParseCommandLine function was the only place where CommandLineToArgv was called, so with it removed, the entire native methods class here can be removed. --- .../engine/NativeCommandParameterBinder.cs | 56 +------------------ 1 file changed, 1 insertion(+), 55 deletions(-) diff --git a/src/System.Management.Automation/engine/NativeCommandParameterBinder.cs b/src/System.Management.Automation/engine/NativeCommandParameterBinder.cs index 50a4675ccd..102ba2edeb 100644 --- a/src/System.Management.Automation/engine/NativeCommandParameterBinder.cs +++ b/src/System.Management.Automation/engine/NativeCommandParameterBinder.cs @@ -16,11 +16,6 @@ namespace System.Management.Automation /// internal class NativeCommandParameterBinder : ParameterBinderBase { - #region tracer - [TraceSource("NativeCommandParameterBinder","The parameter binder for native commands")] - static private PSTraceSource tracer = PSTraceSource.GetTracer ("NativeCommandParameterBinder", "The parameter binder for native commands"); - #endregion tracer - #region ctor /// @@ -129,21 +124,7 @@ namespace System.Management.Automation { get { - var rawArgs = arguments.ToString(); - - if (tracer.IsEnabled && Platform.IsWindows) - { - // This tracing really shouldn't be in the property getter... - tracer.WriteLine("Raw argument string: {0}", rawArgs); - string[] parsedArguments = CommandLineParameterBinderNativeMethods.PreParseCommandLine(rawArgs); - - for (int counter = 0; counter < parsedArguments.Length; counter++) - { - tracer.WriteLine("Argument {0}: {1}", counter, parsedArguments[counter]); - } - } - - return rawArgs; + return arguments.ToString(); } } // Arguments private readonly StringBuilder arguments = new StringBuilder(); @@ -250,39 +231,4 @@ namespace System.Management.Automation #endregion private members } - internal static class CommandLineParameterBinderNativeMethods - { - public static string[] PreParseCommandLine(string commandLine) - { - int numberOfArguments = 0; - IntPtr parsedCommandLine = CommandLineToArgvW(commandLine, out numberOfArguments); - - if(parsedCommandLine == IntPtr.Zero) - return null; - - try - { - string[] results = new string[numberOfArguments - 1]; - for (int counter = 1; counter < numberOfArguments; counter++) - { - results[counter - 1] = Marshal.PtrToStringUni( - Marshal.ReadIntPtr(parsedCommandLine, counter * IntPtr.Size)); - } - - return results; - } - finally - { - LocalFree(parsedCommandLine); - } - } - - [DllImport(PinvokeDllNames.CommandLineToArgvDllName, SetLastError = true)] - static extern IntPtr CommandLineToArgvW( - [MarshalAs(UnmanagedType.LPWStr)] string lpCmdLine, - out int pNumArgs); - - [DllImport(PinvokeDllNames.LocalFreeDllName)] - static extern IntPtr LocalFree(IntPtr hMem); - } } // namespace System.Management.Automation