I have a requirement where I need to Deserialize and Create few objects of a class(Table) which doesn't have a Default Constructor.
Snippet of my code
else if (reader.Name == "Tables")
{
reader.ReadStartElement();
tables = SerializationHelper<Table>.DeserializeList(reader);
}
The definition of DeserializeList in SerializationHelper is as below:
public static List<T> DeserializeList(XmlReader reader)
{
XmlSerializer ser = new XmlSerializer(typeof(T));
List<T> returnval = new List<T>();
while (reader.NodeType != XmlNodeType.EndElement)
{
T result = (T)ser.Deserialize(reader);
returnval.Add(result);
}
return returnval;
}
This is an existing working code and with recent changes we had to add a mandate parameter to all the Constructors in the Class
The Table class here doesn't have any Parameter-less Constructor now.
I wanted to find out if I can by anyway pass-on at-least one parameter when DeSerializing the Table objects.
I have already Read the following but they use JSON.net which in my case is not an option to use.
JSON.net: how to deserialize without using the default constructor?