using System.Text.RegularExpressions; using OneOf; namespace StabilityMatrix.Core.Processes; public partial class ProcessArgs : OneOfBase { /// private ProcessArgs(OneOf input) : base(input) { } // Implicit conversions public static implicit operator ProcessArgs(string input) => new(input); public static implicit operator ProcessArgs(string[] input) => new(input); public static implicit operator string(ProcessArgs input) => input.Match(str => str, arr => string.Join(' ', arr.Select(ProcessRunner.Quote))); public static implicit operator string[](ProcessArgs input) => input.Match( str => ArgumentsRegex().Matches(str).Select(x => x.Value.Trim('"')).ToArray(), arr => arr ); [GeneratedRegex("""[\"].+?[\"]|[^ ]+""", RegexOptions.IgnoreCase)] private static partial Regex ArgumentsRegex(); }