1
function SerializeObject(pObject : Object)
{
   var XmlizedString : String  = null;
   var memoryStream : MemoryStream  = new MemoryStream();
   var xs : XmlSerializer = new XmlSerializer(typeof(XmlData));
   var xmlTextWriter : XmlTextWriter  = new XmlTextWriter(memoryStream, Encoding.UTF8);
   xs.Serialize(xmlTextWriter, pObject);
   memoryStream = xmlTextWriter.BaseStream;
   XmlizedString = UTF8ByteArrayToString(memoryStream.ToArray());
   return XmlizedString;
}

问题在于:

memoryStream = xmlTextWriter.BaseStream;

我知道 xmlTextWriter.BaseStream 属于流类型,但是我将如何进行类型转换呢?

感谢您在高级的任何帮助!

4

1 回答 1

1

您可以使用as参考类型。

尝试:

memoryStream = xmlTextWriter.BaseStream as MemoryStream;

有关更多详细信息,请参阅此问题:如何在 UnityScript 中执行显式类型转换?

于 2012-11-13T08:09:36.580 回答