OptionComponent.cs 541 B

1234567891011121314151617181920212223242526
  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; set; }
  16. public void Awake(string[] args)
  17. {
  18. Parser.Default.ParseArguments<Options>(args)
  19. .WithNotParsed(error => throw new Exception($"命令行格式错误!"))
  20. .WithParsed(options => { Options = options; });
  21. }
  22. }
  23. }