Exemple #1
0
 public Argument(string flag, string template = "{flag} {value}", QuotePolicy quotePolicy = QuotePolicy.WHEN_NECESSARY, EnumCasePolicy enumCase = EnumCasePolicy.LOWERCASE, int order = 0)
 {
     this.Flag        = flag?.ToLower() ?? throw new Exception("Flag can not be null!");
     this.Template    = template?.ToLower() ?? throw new Exception("Template can not be null!");
     this.QuotePolicy = quotePolicy;
     this.EnumCase    = enumCase;
     this.Order       = order;
 }
        public virtual string QuoteFlagValue(QuotePolicy policy, string value)
        {
            bool containsWhitespace = value.Contains(' ');
            bool notAlphaNumeric    = !value.All(char.IsLetterOrDigit);

            if (policy == QuotePolicy.ALWAYS || (policy == QuotePolicy.WHEN_NECESSARY && (containsWhitespace || notAlphaNumeric)))
            {
                return(string.Format("\"{0}\"", value));
            }
            return(value);
        }
Exemple #3
0
        /// <summary>
        /// Quotes and returns the given <paramref name="value"/> if the <paramref name="policy"/> matches the content of the given value.
        /// </summary>
        /// <param name="policy">The <see cref="QuotePolicy"/> to check for.</param>
        /// <param name="value">The string value to apply the <see cref="QuotePolicy"/>.</param>
        /// <returns>A quoted or unquoted variant of <paramref name="value"/>.</returns>
        protected virtual string QuoteValue(QuotePolicy policy, string value)
        {
            bool containsWhitespace = value.Contains(' ');
            bool notAlphaNumeric    = !value.All(char.IsLetterOrDigit);

            if (policy == QuotePolicy.Always || (policy == QuotePolicy.WhenNecessary && (containsWhitespace || notAlphaNumeric)))
            {
                return(string.Format("\"{0}\"", value));
            }
            return(value);
        }