OptionsComponent.cs 700 B

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using System.IO;
  3. using Base;
  4. using CommandLine;
  5. namespace Model
  6. {
  7. [ObjectEvent]
  8. public class OptionsComponentEvent : ObjectEvent<OptionsComponent>, IAwake<string[]>
  9. {
  10. public void Awake(string[] args)
  11. {
  12. this.GetValue().Awake(args);
  13. }
  14. }
  15. public class OptionsComponent: Component
  16. {
  17. public CommandLines AllOptions = new CommandLines();
  18. public Options Options = new Options();
  19. public void Awake(string[] args)
  20. {
  21. string s = File.ReadAllText("./CommandLineConfig.txt");
  22. this.AllOptions = MongoHelper.FromJson<CommandLines>(s);
  23. if (!Parser.Default.ParseArguments(args, this.Options))
  24. {
  25. throw new Exception($"命令行格式错误!");
  26. }
  27. }
  28. }
  29. }