From f878530184b953cbbcc9ca47c431cfdd14fe0f32 Mon Sep 17 00:00:00 2001 From: ww-rm Date: Sun, 26 Oct 2025 16:30:13 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SpineViewerCLI/ExportCommand.cs | 9 +-------- SpineViewerCLI/Extension.cs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 8 deletions(-) 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); + } + } } }