strip out some duplication

This commit is contained in:
Chris Forbes
2010-03-17 23:36:36 +13:00
parent 2feec44df1
commit c17459310a
2 changed files with 5 additions and 10 deletions

View File

@@ -29,26 +29,21 @@ namespace OpenRA.FileFormats
public static void Load(object self, IniSection ini)
{
foreach (var x in ini)
{
var field = self.GetType().GetField(x.Key.Trim());
if (field == null)
throw new NotImplementedException("Missing field `{0}` on `{1}`".F(x.Key.Trim(), self.GetType().Name));
field.SetValue(self, GetValue(field.FieldType, x.Value.Trim()));
}
LoadField(self, x.Key, x.Value);
}
public static void Load(object self, MiniYaml my)
{
foreach (var x in my.Nodes)
LoadField( self, x.Key, x.Value );
LoadField( self, x.Key, x.Value.Value );
}
public static void LoadField( object self, string key, MiniYaml value )
public static void LoadField( object self, string key, string value )
{
var field = self.GetType().GetField( key.Trim() );
if( field == null )
throw new NotImplementedException( "Missing field `{0}` on `{1}`".F( key.Trim(), self.GetType().Name ) );
field.SetValue( self, GetValue( field.FieldType, value.Value ) );
field.SetValue( self, GetValue( field.FieldType, value ) );
}
public static object GetValue( Type fieldType, string x )

View File

@@ -16,7 +16,7 @@ namespace OpenRA
foreach (var c in child.Value.Nodes)
widget.AddChild(LoadWidget(c));
else
FieldLoader.LoadField(widget, child.Key, child.Value);
FieldLoader.LoadField(widget, child.Key, child.Value.Value);
}
return widget;
}