public ArgumentInstance(ArgumentDescriptor descriptor, string value)
 {
     if (descriptor == null)
     {
         throw new ArgumentNullException("descriptor");
     }
     this.descriptor = descriptor;
     this.value = value;
 }
Esempio n. 2
0
 public ArgumentInstance(ArgumentDescriptor descriptor, string value)
 {
     Descriptor = descriptor ?? throw new ArgumentNullException("descriptor");
     Value      = value;
 }
        private static string TryGetMatchingPrefix(ArgumentDescriptor descriptor, string argument)
        {
            Debug.Assert(descriptor.Prefixes.Count(p => argument.StartsWith(p, ArgumentDescriptor.IdComparison)) < 2,
                "Not expecting the argument to match multiple prefixes");

            string match = null;
            if (descriptor.IsVerb)
            {
                // Verbs match the whole argument
                match = descriptor.Prefixes.FirstOrDefault(p => ArgumentDescriptor.IdComparer.Equals(p, argument));
            }
            else
            {
                // Prefixes only match the start
                match = descriptor.Prefixes.FirstOrDefault(p => argument.StartsWith(p, ArgumentDescriptor.IdComparison));
            }
            return match;
        }
        /// <summary>
        /// Attempts to find a descriptor for the current argument
        /// </summary>
        /// <param name="argument">The argument passed on the command line</param>
        /// <param name="descriptor">The descriptor that matches the argument</param>
        /// <param name="prefix">The specific prefix that was matched</param>
        private bool TryGetMatchingDescriptor(string argument, out ArgumentDescriptor descriptor, out string prefix)
        {
            descriptor = null;
            prefix = null;

            bool found = false;

            foreach (ArgumentDescriptor item in this.descriptors)
            {
                string match = TryGetMatchingPrefix(item, argument);
                if (match != null)
                {
                    descriptor = item;
                    prefix = match;
                    found = true;
                    break;
                }
            }
            return found;
        }