Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public object CMDLine(string[] args, string nameClass)
- {
- Type t = Type.GetType(NS + "." + nameClass);
- object obj = Activator.CreateInstance(t);
- foreach (FieldInfo fi in t.GetFields())
- {
- var parameter = fi.GetCustomAttributes(typeof(CommandLineAttribute), false);
- foreach (var par in parameter.Cast<CommandLineAttribute>())
- {
- string s1 = fi.FieldType.Name;
- string s = "-" + par.CommandSwitch + "=";
- string st;
- foreach (string arg in args)
- {
- if (arg.Contains(s))
- {
- int n = arg.IndexOf(s);
- st = arg.Remove(n, s.Length);
- var result = Convert.ChangeType(st, fi.FieldType);
- fi.SetValue(obj, result);
- }
- }
- }
- }
- return obj;
- }
- }
- class CommandLineAttribute : Attribute
- {
- public string CommandSwitch;
- public CommandLineAttribute(string CommandSwitch)
- {
- this.CommandSwitch = CommandSwitch;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement