public void Run(string[] args)
{
Getopt = new Getopt(args);
CommandEntries = new List<CommandEntry>();
foreach (var Member in this.GetType().GetMembers(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
{
var DescriptionAttribute = Member.GetSingleAttribute<DescriptionAttribute>();
var ValuesAttribute = Member.GetSingleAttribute<ValuesAttribute>();
var CommandDefaultAttribute = Member.GetSingleAttribute<CommandDefaultAttribute>();
if (CommandDefaultAttribute != null)
{
if (Member is MethodInfo)
{
BindDefaultMethod(CommandDefaultAttribute, Member as MethodInfo);
}
}
var CommandAttribute = Member.GetSingleAttribute<CommandAttribute>();
if (CommandAttribute != null)
{
var CommandEntry = new CommandEntry()
{
Aliases = CommandAttribute.Aliases,
MemberInfo = Member,
Examples = Member.GetAttribute<ExampleAttribute>().Select(Item => Item.Example).ToArray(),
Description = (DescriptionAttribute != null) ? DescriptionAttribute.Description : "",
Values = (ValuesAttribute != null) ? ValuesAttribute.Values : new object[0],
};
CommandEntries.Add(CommandEntry);
if (Member is MethodInfo)
{
BindMethod(CommandEntry);
}
else if (Member is FieldInfo)
{
BindField(CommandEntry);
}
else
{
throw(new NotImplementedException("Don't know how to handle type " + Member.GetType()));
}
}
}
try
{
Getopt.Process();
}
catch (TargetInvocationException TargetInvocationException)
{
Console.Error.WriteLine(TargetInvocationException.InnerException);
Environment.Exit(-1);
}
catch (Exception Exception)
{
//Console.Error.WriteLine(Exception.Message);
Console.Error.WriteLine(Exception);
Environment.Exit(-2);
}
if (Debugger.IsAttached)
{
Console.ReadKey();
}
}
}