add IEnum<T>.JoinWith, use it to clean up a bunch of things

This commit is contained in:
Chris Forbes
2011-10-30 10:38:02 +13:00
parent 8111ccbea6
commit f83c9fd4d7
17 changed files with 35 additions and 25 deletions

View File

@@ -171,5 +171,10 @@ namespace OpenRA
++v;
return v;
}
public static string JoinWith<T>(this IEnumerable<T> ts, string j)
{
return string.Join(j, ts.Select(t => t.ToString()).ToArray());
}
}
}

View File

@@ -330,7 +330,7 @@ namespace OpenRA.FileFormats
if (f.FieldType.IsArray)
{
var elems = ((Array)v).OfType<object>();
return string.Join(",", elems.Select(a => a.ToString()).ToArray());
return elems.JoinWith(",");
}
return v.ToString();

View File

@@ -228,7 +228,7 @@ namespace OpenRA.FileFormats
if (throwErrors)
if (noInherit.ContainsValue(false))
throw new YamlException("Bogus yaml removals: {0}".F(
string.Join(", ", noInherit.Where(x => !x.Value).Select(x => x.Key).ToArray())));
noInherit.Where(x => !x.Value).JoinWith(", ")));
return ret;
}
@@ -271,7 +271,7 @@ namespace OpenRA.FileFormats
public static string WriteToString(this MiniYamlNodes y)
{
return string.Join("\n", y.ToLines(true).Select(x => x.TrimEnd()).ToArray());
return y.ToLines(true).Select(x => x.TrimEnd()).JoinWith("\n");
}
public static IEnumerable<string> ToLines(this MiniYamlNodes y, bool lowest)

View File

@@ -57,7 +57,7 @@ namespace OpenRA.FileFormats
public override string ToString()
{
return string.Join(",", BitAllocator<T>.GetStrings(Value).ToArray());
return BitAllocator<T>.GetStrings(Value).JoinWith(",");
}
public override int GetHashCode() { return Value.GetHashCode(); }