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属于类型流,但是如何进行类型转换呢?
感谢先进的任何帮助!
答案 0 :(得分:1)
您可以将as
用于参考类型。
尝试:
memoryStream = xmlTextWriter.BaseStream as MemoryStream;
有关详细信息,请参阅此问题:How to perform Explicit typecasting in UnityScript?