- Home /
Which is first, Xml Assignment or Constructor?
If I were to deserialize an xml and it assign to a new object, such as this:
[XmlRoot("TileArray")]
public class TileArray
{
[XmlArray("TileCollection")]
[XmlArrayItem("Tile")]
public List<Tile> TileCollection = new List<Tile>();
}
When the "Tile" objects are created in the list and XML elements are assigned to it, say, like this:
public class Tile
{
[XmlElement("id")]
public ushort tileNumber;
}
Would the "tileNumber" variable be assigned to the Tile object first, and then the Tile object constructor called, or the other way around?
Answer by Masterben135 · Jul 25, 2014 at 02:48 PM
Turns out, the constructor is called first, when it's added to the list. After that, the variables are assigned.
Your answer
![](https://koobas.hobune.stream/wayback/20220613154328im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
What are the pros and cons of ScriptableObjects vs. JSON for data files? 2 Answers
How do you use serialized values at creation? 1 Answer
Deserializing data with XML Serializer 0 Answers
ScriptableObject+XmlSerializer=sad 2 Answers
Trying to XML serialize objects, getting error that UnityEngine.Transform doesn't implement Add() 1 Answer