/// <summary> /// Converts <see cref="Operation"/> to a well-formed string that can be used as command line input /// </summary> public string ToCommandLine(PathTable pathTable, bool escapeResult = false) { PathTable = pathTable; StringBuilder sb = new StringBuilder(); sb.Append(((int)OpType).ToString(System.Globalization.CultureInfo.CurrentCulture)); var orderOfArgs = new string[] { Path.IsValid?FileOrDirectoryToString(Path) : null, Content, LinkPath.IsValid ? FileOrDirectoryToString(LinkPath) : null, SymLinkFlag.ToString(), AdditionalArgs // The process as a test executable does not use the DoNotInfer field }; foreach (var arg in orderOfArgs) { sb.Append(OperationArgsDelimiter); if (arg != null) { sb.Append(arg.ToString()); } } return(escapeResult ? CommandLineEscaping.EscapeAsCommandLineWord(sb.ToString()) : sb.ToString()); }
private static IEnumerable <string> ConvertArgumentsToStringArray(PipData pipData, PathTable pathTable) { var result = new List <string>(); foreach (PipFragment fragment in pipData) { Contract.Assume(fragment.FragmentType != PipFragmentType.Invalid); string s = string.Empty; switch (fragment.FragmentType) { case PipFragmentType.StringLiteral: s = pathTable.StringTable.GetString(fragment.GetStringIdValue()); break; case PipFragmentType.AbsolutePath: s = fragment.GetPathValue().ToString(pathTable); break; case PipFragmentType.NestedFragment: s = fragment.GetNestedFragmentValue().ToString(pathTable); break; default: Contract.Assert(false, "Unhandled fragment type"); break; } if (pipData.FragmentEscaping == PipDataFragmentEscaping.CRuntimeArgumentRules) { s = CommandLineEscaping.EscapeAsCommandLineWord(s); } s += pathTable.StringTable.GetString(pipData.FragmentSeparator); result.Add(s); } return(result); }