重构
This commit is contained in:
@@ -269,14 +269,7 @@ namespace SpineViewerCLI
|
|||||||
r.AddError($"{OptSpeed.Name} must be non-negative.");
|
r.AddError($"{OptSpeed.Name} must be non-negative.");
|
||||||
});
|
});
|
||||||
|
|
||||||
// 用反射查找自己所有的公开属性是 Argument 或者 Option 的
|
this.AddArgsAndOpts();
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
SetAction(ExportAction);
|
SetAction(ExportAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ using SFML.System;
|
|||||||
using Spine;
|
using Spine;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.CommandLine;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@@ -84,5 +86,20 @@ namespace SpineViewerCLI
|
|||||||
}
|
}
|
||||||
return bounds;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user