public static UpdateArgs Parse(string[] args)
{
/*
* ToolUpdater.exe /n "シャルロッテ" /p "D:\Tools\Charlotte" /u "http://192.168.47.74:8020/Charlotte/Update?v=1.12"
* のようなコマンドライン引数をパース
*/
var obj = new UpdateArgs
{
StepDelay = 400,
};
PropertyInfo property = null;
foreach (var s in args.Where(x => x.Length > 0))
{
// スラッシュまたはハイフンで始まる場合をキーとみなす
var c = s[0];
if (c == '/' || c == '-')
{
// キーに一致するプロパティを取得
_propertyDic.TryGetValue(s.Substring(1), out property);
// プロパティが Boolean の場合は指定された時点で true をセット
if (property.PropertyType == typeof(bool))
{
property.SetValue(obj, true);
property = null;
}
continue;
}
// 直前のコマンドライン引数がプロパティのキーだった場合は、今回の文字列を値とみなす
if (property != null)
{
property.SetValue(obj, s);
}
property = null;
}
return obj;
}