move WithDefault onto Exts
This commit is contained in:
@@ -24,6 +24,12 @@ namespace OpenRA
|
|||||||
return string.Format(fmt, args);
|
return string.Format(fmt, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static T WithDefault<T>(T def, Func<T> f)
|
||||||
|
{
|
||||||
|
try { return f(); }
|
||||||
|
catch { return def; }
|
||||||
|
}
|
||||||
|
|
||||||
public static void Do<T>(this IEnumerable<T> e, Action<T> fn)
|
public static void Do<T>(this IEnumerable<T> e, Action<T> fn)
|
||||||
{
|
{
|
||||||
foreach (var ee in e)
|
foreach (var ee in e)
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace OpenRA.Utility
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var action = WithDefault( null, () => actions[args[0]]);
|
var action = Exts.WithDefault( null, () => actions[args[0]]);
|
||||||
if (action == null)
|
if (action == null)
|
||||||
PrintUsage();
|
PrintUsage();
|
||||||
else
|
else
|
||||||
@@ -61,12 +61,6 @@ namespace OpenRA.Utility
|
|||||||
Console.WriteLine(" --extract MOD[,MOD]* FILES Extract files from mod packages");
|
Console.WriteLine(" --extract MOD[,MOD]* FILES Extract files from mod packages");
|
||||||
}
|
}
|
||||||
|
|
||||||
static T WithDefault<T>(T def, Func<T> f)
|
|
||||||
{
|
|
||||||
try { return f(); }
|
|
||||||
catch { return def; }
|
|
||||||
}
|
|
||||||
|
|
||||||
static string GetNamedArg(string[] args, string arg)
|
static string GetNamedArg(string[] args, string arg)
|
||||||
{
|
{
|
||||||
if (args.Length < 2)
|
if (args.Length < 2)
|
||||||
|
|||||||
Reference in New Issue
Block a user