Esempio n. 1
0
        public override string Convert(string argName, object value)
        {
            if (value is IDictionary <string, string> dictionary)
            {
                var builder = new StringBuilder();

                foreach (var pair in dictionary)
                {
                    if (builder.Length > 0)
                    {
                        builder.Append(" ");
                    }

                    string escapedValue = ArgumentSerializationUtility.EscapeValue($"\"{pair.Value}\"");

                    builder.Append(base.Convert(argName, $"{pair.Key}={escapedValue}"));
                }

                return(builder.ToString() ?? string.Empty);
            }

            throw new NotSupportedException($"{nameof(value)} must be of type IDictionary<string, string>.");
        }
Esempio n. 2
0
        public override string Convert(string argName, object value)
        {
            if (value is IEnumerable <Option> options)
            {
                var builder = new StringBuilder();

                foreach (var option in options)
                {
                    if (builder.Length > 0)
                    {
                        builder.Append(":");
                    }

                    bool hasName = false;

                    if (!string.IsNullOrWhiteSpace(option?.Name))
                    {
                        hasName = true;
                        builder.Append($"{option.Name}");
                    }

                    if (!string.IsNullOrWhiteSpace(option?.Value))
                    {
                        if (hasName)
                        {
                            builder.Append("=");
                        }
                        builder.Append(ArgumentSerializationUtility.EscapeValue(option.Value));
                    }
                }

                return(builder.Length > 0 ? base.Convert(argName, builder) : string.Empty);
            }

            throw new NotSupportedException($"{nameof(value)} must be of type IEnumerable<Option>.");
        }