diff --git a/SpineViewerCLI/ExportCommand.cs b/SpineViewerCLI/ExportCommand.cs index a2289a9..2af94ef 100644 --- a/SpineViewerCLI/ExportCommand.cs +++ b/SpineViewerCLI/ExportCommand.cs @@ -269,14 +269,7 @@ namespace SpineViewerCLI r.AddError($"{OptSpeed.Name} must be non-negative."); }); - // 用反射查找自己所有的公开属性是 Argument 或者 Option 的 - foreach (var prop in GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) - { - var value = prop.GetValue(this); - if (value is Argument arg) Add(arg); - else if (value is Option opt) Add(opt); - } - + this.AddArgsAndOpts(); SetAction(ExportAction); } diff --git a/SpineViewerCLI/Extension.cs b/SpineViewerCLI/Extension.cs index b5b3257..87d1a91 100644 --- a/SpineViewerCLI/Extension.cs +++ b/SpineViewerCLI/Extension.cs @@ -3,7 +3,9 @@ using SFML.System; using Spine; using System; using System.Collections.Generic; +using System.CommandLine; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; @@ -84,5 +86,20 @@ namespace SpineViewerCLI } return bounds; } + + /// + /// 自动添加所有能找到的类型是 或者 的公开属性 + /// + /// + public static void AddArgsAndOpts(this Command self) + { + // 用反射查找自己所有的公开属性是 Argument 或者 Option 的 + foreach (var prop in self.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) + { + var value = prop.GetValue(self); + if (value is Argument arg) self.Add(arg); + else if (value is Option opt) self.Add(opt); + } + } } }