Load/Save settings from <support dir>/settings.yaml

This commit is contained in:
Paul Chote
2010-07-10 14:58:50 +12:00
parent b7eb4193d4
commit 04bb5b0a4b
4 changed files with 64 additions and 28 deletions

View File

@@ -132,6 +132,19 @@ namespace OpenRA.FileFormats
f => f.Name,
f => new MiniYaml(FormatValue(o, f))));
}
public static MiniYaml SaveDifferences(object o, object from)
{
if (o.GetType() != from.GetType())
throw new InvalidOperationException("FieldLoader: can't diff objects of different types");
var fields = o.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance)
.Where(f => FormatValue(o,f) != FormatValue(from,f));
return new MiniYaml(null, fields.ToDictionary(
f => f.Name,
f => new MiniYaml(FormatValue(o, f))));
}
public static string FormatValue(object o, FieldInfo f)
{