OptionComponent.cs 498 B

123456789101112131415161718192021222324252627
  1. using System;
  2. using CommandLine;
  3. namespace Model
  4. {
  5. [ObjectEvent]
  6. public class OptionComponentEvent : ObjectEvent<OptionComponent>, IAwake<string[]>
  7. {
  8. public void Awake(string[] args)
  9. {
  10. this.Get().Awake(args);
  11. }
  12. }
  13. public class OptionComponent : Component
  14. {
  15. public Options Options { get; } = new Options();
  16. public void Awake(string[] args)
  17. {
  18. if (!Parser.Default.ParseArguments(args, this.Options))
  19. {
  20. throw new Exception($"命令行格式错误!");
  21. }
  22. }
  23. }
  24. }