public void Save(string filepath) { var root = new List <MiniYamlNode>(); var gen = new List <MiniYamlNode>(); foreach (var field in fields) { FieldInfo f = this.GetType().GetField(field); if (f.GetValue(this) == null) { continue; } gen.Add(new MiniYamlNode(field, FieldSaver.FormatValue(this, f))); } root.Add(new MiniYamlNode("General", null, gen)); root.Add(new MiniYamlNode("Terrain", null, Terrain.Select(t => new MiniYamlNode( "TerrainType@{0}".F(t.Value.Type), t.Value.Save())).ToList())); root.Add(new MiniYamlNode("Templates", null, Templates.Select(t => new MiniYamlNode( "Template@{0}".F(t.Value.Id), t.Value.Save())).ToList())); root.WriteToFile(filepath); }
public MiniYaml Save() { var root = new List<MiniYamlNode>(); foreach (var field in Fields) { FieldInfo f = this.GetType().GetField(field); if (f.GetValue(this) == null) continue; root.Add( new MiniYamlNode( field, FieldSaver.FormatValue( this, f ) ) ); } root.Add( new MiniYamlNode( "Tiles", null, Tiles.Select( x => new MiniYamlNode( x.Key.ToString(), x.Value ) ).ToList() ) ); return new MiniYaml(null, root); }
public static MiniYamlNode SaveField(object o, string field) { return(new MiniYamlNode(field, FieldSaver.FormatValue(o, o.GetType().GetField(field)))); }