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;
}

The problem lies in the line:

memoryStream = xmlTextWriter.BaseStream;

I am aware that xmlTextWriter.BaseStream is of the type stream, but how would I go about typecasting it?

thanks for any help in advanced!

Paolo Moretti
  • 54,162
  • 23
  • 101
  • 92
smeddles24
  • 101
  • 1
  • 1
  • 8
  • I'm not sure how this is related to JavaScript?? – freakish Nov 13 '12 at 07:51
  • Are you sure that's javascript? Also, if those classes are anything like I'd expect, why do you need to extract the `BaseStream` from the `xmlTextWriter`? Isn't it just the same stream that was already referenced by the `memoryStream` variable, and passed into the `XmlTestWriter` constructor? – Damien_The_Unbeliever Nov 13 '12 at 07:52
  • its javascript, but applied to Unity3D – smeddles24 Nov 13 '12 at 07:53

1 Answers1

1

You can use as for reference types.

Try:

memoryStream = xmlTextWriter.BaseStream as MemoryStream;

See this question for more details: How to perform Explicit typecasting in UnityScript?

Paolo Moretti
  • 54,162
  • 23
  • 101
  • 92