我目前正在开发一个Sprite版本工具,该工具可以通过单击Spritesheet中的Sprite来用该Sprite的ID,位置和大小填充DataGridView,然后按一下按钮,将这些行导出到XML文件中,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfModule xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Module>
<ID>0</ID>
<posx>247</posx>
<posy>87</posy>
<width>36</width>
<height>72</height>
</Module>
<Module>
<ID>1</ID>
<posx>197</posx>
<posy>87</posy>
<width>32</width>
<height>70</height>
</Module>
</ArrayOfModule>
我为此使用XmlSerializer。我用这5个属性来确定类型模块的列表。事情是,我想添加一个新标签,该标签不是模块类的属性,该属性代表用于精灵表的图像,因此我可以同时导入这些模块和图像。我想要我的XML像这样:
<?xml version="1.0" encoding="utf-8"?>
<Image>C:\sprite_sheet.png</Image>
<ArrayOfModule xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Module>
<ID>0</ID>
<posx>247</posx>
<posy>87</posy>
<width>36</width>
<height>72</height>
</Module>
</ArrayOfModule>
我怎样才能做到这一点?我可以使用XmlSerializer进行此操作,还是需要其他内容?
您必须创建一个包装器类:
public class AllInfo
{
public string Image {get;set;}
public Module[] Modules {get;set;}
}
当您将此类的实例传递给序列化程序时,它将序列化这两条信息。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句