Use pattern matching in FieldSaver
This commit is contained in:
@@ -72,32 +72,14 @@ namespace OpenRA
|
|||||||
return "";
|
return "";
|
||||||
|
|
||||||
var t = v.GetType();
|
var t = v.GetType();
|
||||||
|
|
||||||
if (t == typeof(Color))
|
|
||||||
{
|
|
||||||
return ((Color)v).ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (t == typeof(Rectangle))
|
|
||||||
{
|
|
||||||
var r = (Rectangle)v;
|
|
||||||
return "{0},{1},{2},{3}".F(r.X, r.Y, r.Width, r.Height);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(BitSet<>))
|
if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(BitSet<>))
|
||||||
{
|
|
||||||
return ((IEnumerable<string>)v).Select(FormatValue).JoinWith(", ");
|
return ((IEnumerable<string>)v).Select(FormatValue).JoinWith(", ");
|
||||||
}
|
|
||||||
|
|
||||||
if (t.IsArray && t.GetArrayRank() == 1)
|
if (t.IsArray && t.GetArrayRank() == 1)
|
||||||
{
|
|
||||||
return ((Array)v).Cast<object>().Select(FormatValue).JoinWith(", ");
|
return ((Array)v).Cast<object>().Select(FormatValue).JoinWith(", ");
|
||||||
}
|
|
||||||
|
|
||||||
if (t.IsGenericType && (t.GetGenericTypeDefinition() == typeof(HashSet<>) || t.GetGenericTypeDefinition() == typeof(List<>)))
|
if (t.IsGenericType && (t.GetGenericTypeDefinition() == typeof(HashSet<>) || t.GetGenericTypeDefinition() == typeof(List<>)))
|
||||||
{
|
|
||||||
return ((System.Collections.IEnumerable)v).Cast<object>().Select(FormatValue).JoinWith(", ");
|
return ((System.Collections.IEnumerable)v).Cast<object>().Select(FormatValue).JoinWith(", ");
|
||||||
}
|
|
||||||
|
|
||||||
// This is only for documentation generation
|
// This is only for documentation generation
|
||||||
if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Dictionary<,>))
|
if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Dictionary<,>))
|
||||||
@@ -118,11 +100,8 @@ namespace OpenRA
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Primitives.Cache<,>))
|
if (v is DateTime d)
|
||||||
return ""; // TODO
|
return d.ToString("yyyy-MM-dd HH-mm-ss", CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
if (t == typeof(DateTime))
|
|
||||||
return ((DateTime)v).ToString("yyyy-MM-dd HH-mm-ss", CultureInfo.InvariantCulture);
|
|
||||||
|
|
||||||
// Try the TypeConverter
|
// Try the TypeConverter
|
||||||
var conv = TypeDescriptor.GetConverter(t);
|
var conv = TypeDescriptor.GetConverter(t);
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ namespace OpenRA.Primitives
|
|||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return string.Format("{{X={0},Y={1},Width={2},Height={3}}}", X, Y, Width, Height);
|
return "{0},{1},{2},{3}".F(X, Y, Width, Height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user