This commit is contained in:
ww-rm
2025-10-26 16:30:13 +08:00
parent 81d9224658
commit f878530184
2 changed files with 18 additions and 8 deletions

View File

@@ -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);
}

View File

@@ -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;
}
/// <summary>
/// 自动添加所有能找到的类型是 <see cref="Argument"/> 或者 <see cref="Option"/> 的公开属性
/// </summary>
/// <param name="self"></param>
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);
}
}
}
}