Framework is c# .net 4.6.2
I am generating automatic XML classes from XML codes
When I auto generate, it automatically converts as Array[][]
But i want to use it as List<List<>>
And i am sure that my conversation from Array to List causes some serialization error. I think it is about get and set functions. So i need your help to fix this issue
Here the auto generated code piece when i edit > paste special > paste XML as classes
/// <remarks/>
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class OxFordDefinition_perGroup
{
private string _GroupDescField;
private string _GroupSenseField;
private string _GroupGrammerField;
private OxFordDefinition_perGroup_perMainExample_perSubExample[][] _perMainExampleField;
/// <remarks/>
public string _GroupDesc
{
get
{
return this._GroupDescField;
}
set
{
this._GroupDescField = value;
}
}
/// <remarks/>
public string _GroupSense
{
get
{
return this._GroupSenseField;
}
set
{
this._GroupSenseField = value;
}
}
/// <remarks/>
public string _GroupGrammer
{
get
{
return this._GroupGrammerField;
}
set
{
this._GroupGrammerField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("_perSubExample", typeof(OxFordDefinition_perGroup_perMainExample_perSubExample), IsNullable = false)]
public OxFordDefinition_perGroup_perMainExample_perSubExample[][] _perMainExample
{
get
{
return this._perMainExampleField;
}
set
{
this._perMainExampleField = value;
}
}
}
But instead of arrays, i want to use List<List<>>
So i make it like below
/// <remarks/>
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class OxFordDefinition_perGroup
{
private string _GroupDescField;
private string _GroupSenseField;
private string _GroupGrammerField;
private List<List<OxFordDefinition_perGroup_perMainExample_perSubExample>> _perMainExampleField;
/// <remarks/>
public string _GroupDesc
{
get
{
return this._GroupDescField;
}
set
{
this._GroupDescField = value;
}
}
/// <remarks/>
public string _GroupSense
{
get
{
return this._GroupSenseField;
}
set
{
this._GroupSenseField = value;
}
}
/// <remarks/>
public string _GroupGrammer
{
get
{
return this._GroupGrammerField;
}
set
{
this._GroupGrammerField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("_perSubExample", typeof(OxFordDefinition_perGroup_perMainExample_perSubExample), IsNullable = false)]
public List<List<OxFordDefinition_perGroup_perMainExample_perSubExample>> _perMainExample
{
get
{
return this._perMainExampleField;
}
set
{
this._perMainExampleField = value;
}
}
}
But this time it gives serialization error when i try to serialize like below
public static string SerializeXML<T>(this T toSerialize)
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
StringWriter textWriter = new StringWriter();
xmlSerializer.Serialize(textWriter, toSerialize);
return textWriter.ToString();
}
Here the full code of the XML class
Here the error it gives
See Question&Answers more detail:os