Beispiel #1
0
        public bool Parse(string[] args)
        {
            PropertyInfo[] Infos = typeof(Arguments).GetProperties();
            foreach (var Info in Infos)
            {
                object[] Attributes = Info.GetCustomAttributes(false);

                string Name         = null;
                string DefaultValue = null;

                foreach (var Att in Attributes)
                {
                    if (Att.GetType() == typeof(ArgumentName))
                    {
                        Name = (Att as ArgumentName).Name;
                    }
                    if (Att.GetType() == typeof(DefaultArgument))
                    {
                        DefaultValue = (Att as DefaultArgument).Value;
                    }
                }

                bool found = false;
                foreach (var arg in args)
                {
                    if (arg.StartsWith(Name))
                    {
                        string val = arg.Replace(Name, "");
                        Info.SetValue(this, val);
                        found = true;
                        break;
                    }
                }

                if (!found && DefaultValue != null)
                {
                    Info.SetValue(this, DefaultValue);
                }
                else if (!found && DefaultValue == null)
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #2
0
 public void ShowParsedValues()
 {
     PropertyInfo[] Infos = typeof(Arguments).GetProperties();
     foreach (var Info in Infos)
     {
         object[] Attributes = Info.GetCustomAttributes(false);
         string   Name       = null;
         foreach (var Att in Attributes)
         {
             if (Att.GetType() == typeof(ArgumentName))
             {
                 Name = (Att as ArgumentName).Name;
             }
         }
         if (Info.GetValue(this) != null)
         {
             System.Console.WriteLine("Name: " + Name + " " + Info.GetValue(this).ToString());
         }
     }
 }
Beispiel #3
0
        public void ShowAllOptions()
        {
            PropertyInfo[] Infos = typeof(Arguments).GetProperties();
            foreach (var Info in Infos)
            {
                object[] Attributes = Info.GetCustomAttributes(false);

                string Name         = null;
                string DefaultValue = null;

                foreach (var Att in Attributes)
                {
                    if (Att.GetType() == typeof(ArgumentName))
                    {
                        Name = (Att as ArgumentName).Name;
                    }
                    if (Att.GetType() == typeof(DefaultArgument))
                    {
                        DefaultValue = (Att as DefaultArgument).Value;
                    }
                }
                System.Console.WriteLine("Option: {0}, Default Value {1}", Name, DefaultValue == null ? " None, this option is required " : DefaultValue);
            }
        }