Add empty arrays to xml
This commit is contained in:
1 parent
9e4a14985e
commit
2385f672d0
3 files changed
+20
-1
No files matched your search
@@ -419,7 +419,7 @@ namespace Vocaluxe.Base
|
|||||||
case "Language":
|
case "Language":
|
||||||
return "Game-Language";
|
return "Game-Language";
|
||||||
case "SongFolder":
|
case "SongFolder":
|
||||||
return "SongFolder: SongFolder1, SongFolder2, SongFolder3, ...";
|
return "SongFolder: Add each song folder in a seperate SongFolder entry";
|
||||||
case "SongMenu":
|
case "SongMenu":
|
||||||
return "SongMenu: " + CHelper.ListStrings(Enum.GetNames(typeof(ESongMenu)));
|
return "SongMenu: " + CHelper.ListStrings(Enum.GetNames(typeof(ESongMenu)));
|
||||||
case "SongSorting":
|
case "SongSorting":
|
||||||
|
|||||||
@@ -165,8 +165,14 @@ namespace VocaluxeLib.Xml
|
|||||||
if (field.IsEmbeddedList)
|
if (field.IsEmbeddedList)
|
||||||
{
|
{
|
||||||
IEnumerable values = (IEnumerable)value;
|
IEnumerable values = (IEnumerable)value;
|
||||||
|
bool empty = true;
|
||||||
foreach (object subValue in values)
|
foreach (object subValue in values)
|
||||||
|
{
|
||||||
_WriteValue(writer, field.Name, field.SubType, subValue, field.IsAttribute);
|
_WriteValue(writer, field.Name, field.SubType, subValue, field.IsAttribute);
|
||||||
|
empty = false;
|
||||||
|
}
|
||||||
|
if (empty && _WriteDefaults)
|
||||||
|
writer.WriteElementString(field.Name, "");
|
||||||
}
|
}
|
||||||
else if (field.IsByteArray)
|
else if (field.IsByteArray)
|
||||||
writer.WriteElementString(field.Name, Convert.ToBase64String((byte[])value));
|
writer.WriteElementString(field.Name, Convert.ToBase64String((byte[])value));
|
||||||
|
|||||||
@@ -301,6 +301,11 @@ namespace VocaluxeTests
|
|||||||
<I>2</I>
|
<I>2</I>
|
||||||
<J>3</J>
|
<J>3</J>
|
||||||
</root>";
|
</root>";
|
||||||
|
private const string _XmlListEmb4 = _Head + @"<root>
|
||||||
|
<I>2</I>
|
||||||
|
<Entry />
|
||||||
|
<J>3</J>
|
||||||
|
</root>";
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void TestListEmbedded()
|
public void TestListEmbedded()
|
||||||
@@ -321,6 +326,10 @@ namespace VocaluxeTests
|
|||||||
Assert.AreEqual(foo.Ints.Count, 0, "Deserialization failed");
|
Assert.AreEqual(foo.Ints.Count, 0, "Deserialization failed");
|
||||||
res = ser.Serialize(foo);
|
res = ser.Serialize(foo);
|
||||||
Assert.AreEqual(_XmlListEmb3, res, "Serialization failed");
|
Assert.AreEqual(_XmlListEmb3, res, "Serialization failed");
|
||||||
|
ser = new CXmlSerializer(true);
|
||||||
|
foo.Ints.Clear();
|
||||||
|
res = ser.Serialize(foo);
|
||||||
|
Assert.AreEqual(_XmlListEmb4, res, "Serialization failed");
|
||||||
_AssertFail<SListEmb, CXmlException>(_Empty);
|
_AssertFail<SListEmb, CXmlException>(_Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -343,6 +352,10 @@ namespace VocaluxeTests
|
|||||||
Assert.AreEqual(foo.Ints.Length, 0, "Deserialization failed");
|
Assert.AreEqual(foo.Ints.Length, 0, "Deserialization failed");
|
||||||
res = ser.Serialize(foo);
|
res = ser.Serialize(foo);
|
||||||
Assert.AreEqual(_XmlListEmb3, res, "Serialization failed");
|
Assert.AreEqual(_XmlListEmb3, res, "Serialization failed");
|
||||||
|
ser = new CXmlSerializer(true);
|
||||||
|
foo.Ints = new SEntry[0];
|
||||||
|
res = ser.Serialize(foo);
|
||||||
|
Assert.AreEqual(_XmlListEmb4, res, "Serialization failed");
|
||||||
_AssertFail<SArrayEmb, CXmlException>(_Empty);
|
_AssertFail<SArrayEmb, CXmlException>(_Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user