Ejemplo n.º 1
0
 /// <summary>
 /// Calls AddValidArgument for every ConsoleAction that has a
 /// CommandLineSwitch defined
 /// </summary>
 /// <param name="type"></param>
 public static void AddSwitches(Type type)
 {
     MethodInfo[] methods = type.GetMethods();
     foreach (MethodInfo method in methods)
     {
         ConsoleActionAttribute action = null;
         if (method.HasCustomAttributeOfType <ConsoleActionAttribute>(out action))
         {
             if (!string.IsNullOrEmpty(action.CommandLineSwitch))
             {
                 AddValidArgument(action.CommandLineSwitch, true, addAcronym: true, description: action.Information, valueExample: action.ValueExample);
             }
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Determines if any command line switches were provided as arguments
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static bool ReceivedSwitchArguments(Type type)
        {
            MethodInfo[] methods          = type.GetMethods();
            bool         receivedSwitches = false;

            foreach (MethodInfo method in methods)
            {
                ConsoleActionAttribute action = null;
                if (method.HasCustomAttributeOfType <ConsoleActionAttribute>(out action))
                {
                    if (!string.IsNullOrEmpty(action.CommandLineSwitch) && !receivedSwitches)
                    {
                        receivedSwitches = Arguments.Contains(action.CommandLineSwitch);
                    }
                }
                if (receivedSwitches)
                {
                    break;
                }
            }
            return(receivedSwitches);
        }