Add ability to load and save HashSets.
This commit is contained in:
@@ -429,6 +429,18 @@ namespace OpenRA
|
|||||||
ret.SetValue(GetValue(fieldName, fieldType.GetElementType(), parts[i].Trim(), field), i);
|
ret.SetValue(GetValue(fieldName, fieldType.GetElementType(), parts[i].Trim(), field), i);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
else if (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(HashSet<>))
|
||||||
|
{
|
||||||
|
var set = Activator.CreateInstance(fieldType);
|
||||||
|
if (value == null)
|
||||||
|
return set;
|
||||||
|
|
||||||
|
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
var addMethod = fieldType.GetMethod("Add", fieldType.GetGenericArguments());
|
||||||
|
for (var i = 0; i < parts.Length; i++)
|
||||||
|
addMethod.Invoke(set, new[] { GetValue(fieldName, fieldType.GetGenericArguments()[0], parts[i].Trim(), field) });
|
||||||
|
return set;
|
||||||
|
}
|
||||||
else if (fieldType == typeof(Size))
|
else if (fieldType == typeof(Size))
|
||||||
{
|
{
|
||||||
if (value != null)
|
if (value != null)
|
||||||
|
|||||||
@@ -91,8 +91,12 @@ namespace OpenRA
|
|||||||
|
|
||||||
if (t.IsArray && t.GetArrayRank() == 1)
|
if (t.IsArray && t.GetArrayRank() == 1)
|
||||||
{
|
{
|
||||||
var elems = ((Array)v).OfType<object>();
|
return ((Array)v).Cast<object>().JoinWith(", ");
|
||||||
return elems.JoinWith(", ");
|
}
|
||||||
|
|
||||||
|
if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(HashSet<>))
|
||||||
|
{
|
||||||
|
return ((System.Collections.IEnumerable)v).Cast<object>().JoinWith(", ");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(OpenRA.Primitives.Cache<,>))
|
if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(OpenRA.Primitives.Cache<,>))
|
||||||
|
|||||||
Reference in New Issue
Block a user