PowerArgs.CommandLineArgumentsDefinition.FindMatchingAction C# (CSharp) Method

FindMatchingAction() public method

Finds the first CommandLineAction that matches the given key
public FindMatchingAction ( string key, bool throwIfMoreThanOneMatch = false ) : CommandLineAction
key string The key as if it was typed in on the command line. This can also be an alias.
throwIfMoreThanOneMatch bool If set to true then this method will throw and InvalidArgDeginitionException if more than 1 match is found
return CommandLineAction
        public CommandLineAction FindMatchingAction(string key, bool throwIfMoreThanOneMatch = false)
        {
            var match = from a in Actions where a.IsMatch(key) select a;
            if (match.Count() > 1 && throwIfMoreThanOneMatch)
            {
                throw new InvalidArgDefinitionException("The key '" + key + "' matches more than one action");
            }

            return match.FirstOrDefault();
        }

Usage Example

Beispiel #1
0
        private static bool IsBool(string key, CommandLineArgumentsDefinition definition, ParseResult resultContext)
        {
            var match = definition.FindMatchingArgument(key, true);

            if (match == null)
            {
                var possibleActionContext = resultContext.ImplicitParameters.ContainsKey(0) ? resultContext.ImplicitParameters[0] : null;

                if (possibleActionContext == null)
                {
                    return(false);
                }
                else
                {
                    var actionContext = definition.FindMatchingAction(possibleActionContext, true);
                    if (actionContext == null)
                    {
                        return(false);
                    }

                    match = actionContext.FindMatchingArgument(key, true);
                    if (match == null)
                    {
                        return(false);
                    }
                }
            }

            return(match.ArgumentType == typeof(bool));
        }
All Usage Examples Of PowerArgs.CommandLineArgumentsDefinition::FindMatchingAction