Hi,
I'm not sure why, but XmlSerializer.Serialize(Stream stream, object o)
is broken and produces garbage. Attached is a file that demonstrates the
problem.
In contrast, using XmlSerializer.Serialize(TextWriter textWriter, object
o) works fine.
I poked around for a little bit, but failed to turn up anything obvious,
proving the fact that I'm a newbie to the project.
I did fix one bug to the Serializer for Enum types. I added the
following code to XmlSerializer.cs and verified that the output matched
the output under .NET.
Best regards,
-elan
*** 558,564 ****
}
else if (type.IsEnum)
{
! // FIXME
}
else
{ //Complex Type
--- 558,564 ----
}
else if (type.IsEnum)
{
! writer.WriteString(GetXmlValue(value));
}
else
{ //Complex Type
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System.Text;
// Items in the shopping list
public class Item
{
public RequestType Type;
public Guid RequestId;
public bool KeepAlive;
public string Trove;
public string Data;
public enum RequestType { List, Get }
public Item() {}
public Item(RequestType type,
Guid requestId,
bool keepAlive,
string trove,
string data)
{
Type = type;
RequestId = requestId;
KeepAlive = keepAlive;
Trove = trove;
Data = data;
}
}
public class MainClass
{
static void Main ()
{
Item item = new Item(Item.RequestType.List,
Guid.NewGuid(),
true,
"Trove-1",
"blah");
// Serialization
XmlSerializer s = new XmlSerializer(typeof(Item));
// This doesn't work!
MemoryStream mem = new MemoryStream();
s.Serialize(mem, item);
Console.WriteLine("The data: {0}", Encoding.ASCII.GetString(mem.ToArray()));
// This works!
StringWriter w = new StringWriter();
s.Serialize(w, item);
Console.WriteLine("The data: {0}", w.GetStringBuilder().ToString());
// Deserialization -- NOT IMPLEMENTED.
//Item newItem;
//TextReader r = new StreamReader( "item.xml" );
//newItem = (Item)s.Deserialize(r);
//r.Close();
}
}