protected T GetOptionValue <T>(OptionSpec option)
        {
            if (option == null)
            {
                throw new ArgumentNullException(nameof(option), $"{nameof(option)} is null.");
            }

            TypeConverter  converter = TypeDescriptor.GetConverter(typeof(T));
            IList <string> values;

            if (m_optionValues.TryGetValue(option.Name, out values))
            {
                if (values.Count > 1)
                {
                    throw new InvalidOperationException("GetOptionValue cannot be used to retreive multiple values.");
                }

                if (values.Count == 1)
                {
                    try
                    {
                        return((T)converter.ConvertFromInvariantString(values.Single()));
                    }
                    catch (Exception ex)
                    {
                        throw new FormatException(String.Format("\"{0}\" is not a valid value for option /{1}: {2}", values.Single(), option, ex.Message));
                    }
                }
            }

            throw new KeyNotFoundException(String.Format("Option {0} not specified.", option.Name));
        }
        protected bool HasOption(OptionSpec option)
        {
            if (option == null)
            {
                throw new ArgumentNullException(nameof(option), $"{nameof(option)} is null.");
            }

            return(m_optionValues.ContainsKey(option.Name));
        }
Exemple #3
0
        protected bool HasValue(OptionSpec option)
        {
            IList <string> values;

            if (!m_optionValues.TryGetValue(option.Name, out values))
            {
                return(false);
            }

            return(values.Any(val => val != null));
        }
Exemple #4
0
        protected IList <T> GetOptionValues <T>(OptionSpec option)
        {
            List <T>       result    = new List <T>();
            TypeConverter  converter = TypeDescriptor.GetConverter(typeof(T));
            IList <string> values;

            if (m_optionValues.TryGetValue(option.Name, out values))
            {
                foreach (string value in values.Where(val => val != null))
                {
                    result.Add((T)converter.ConvertFromInvariantString(value));
                }
            }
            return(result);
        }
        protected bool HasValue(OptionSpec option)
        {
            if (option == null)
            {
                throw new ArgumentNullException(nameof(option), $"{nameof(option)} is null.");
            }

            IList <string> values;

            if (!m_optionValues.TryGetValue(option.Name, out values))
            {
                return(false);
            }

            return(values.Any(val => val != null));
        }
Exemple #6
0
 protected bool HasOption(OptionSpec option)
 {
     return(m_optionValues.ContainsKey(option.Name));
 }