var serializer = new XmlSerializer(typeof(MyClass));
using(var stream = new FileStream(path, FileMode.Open))
{
return serializer.Deserialize(stream) as MyClass;
}
Basically, it reads an xml file from “path” and returns it as a MyClass.
But what if instead of having the file’s path, I have a public TextAsset variable referencing the actual file?
How could I deserialize the “textasset” xml file into MyClass?
Well, all you need is to convert the string into a stream. The string can be taken from TextAsset.text
edit
btw the Deserialize method has 6 overloads and one takes a TextReader. TextReader is an abstract base class. You cah use a StringReader (which ia a TextReader) like this:
var serializer = new XmlSerializer(typeof(MyClass));
using(var reader = new System.IO.StringReader(yourTextAsset.text))
{
return serializer.Deserialize(reader) as MyClass;
}