public static string ToString()

in wwauth/Google.Solutions.WWAuth/Util/CommandLineParser.cs [113:150]


        public static string ToString<TOptions>(TOptions options, bool useQuotes = true)
            where TOptions : ICommandLineOptions
        {
            var quote = useQuotes ? "\"" : string.Empty;

            string executablePath = options.Executable;
            if (executablePath.Contains(" ") && !useQuotes)
            {
                //
                // Some client libraries don't support quoted command
                // lines (b/238143555, b/237606033). That's a problem if
                // the executable path itself contains spaces, which is
                // reasonably likely on Windows.
                //
                // As a workaround, convert the executable path to
                // 8.3 notation, which is guaranteed not to include
                // spaces. Then it's safe to drop the quotes.
                //
                var shortNameBuffer = new StringBuilder(260);
                if (NativeMethods.GetShortPathName(
                    executablePath,
                    shortNameBuffer,
                    shortNameBuffer.Capacity) == 0)
                {
                    throw new Win32Exception("Failed to create short-path name for file");
                }

                executablePath = shortNameBuffer.ToString();
                Debug.Assert(!executablePath.Contains(" "));
            }

            return $"{quote}{executablePath}{quote} " + string.Join(
                " ",
                GetSupportedProperties<TOptions>()
                    .Where(p => p.PropertyType.IsEnum ||
                                p.GetValue(options) is string s && !string.IsNullOrEmpty(s))
                    .Select(p => $"/{p.Name} {quote}{p.GetValue(options)}{quote}"));
        }