Running XSD.exe on my xml to generate C# class. All works well except on this property
[System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
[System.Xml.Serialization.XmlArrayItemAttribute("ATTRIBUTES", typeof(DOCUMENTDocumentATTRIBUTES), Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=false)]
public DocumentATTRIBUTES[][] Document {
get {
return this.documentField;
}
set {
this.documentField = value;
}
}
I want to try and use CollectionBase, and this was my attempt
public DocumentATTRIBUTESCollection Document {
get {
return this.documentField;
}
set {
this.documentField = value;
}
}
/// <remarks/>
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class DocumentATTRIBUTES
{
private string _author;
private string _maxVersions;
private string _summary;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string author
{
get
{ return _author; }
set { _author = value; }
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string max_versions
{
get { return _maxVersions; }
set { _maxVersions = value; }
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string summary
{
get { return _summary; }
set { _summary = value; }
}
}
public class DocumentAttributeCollection : System.Collections.CollectionBase
{
public DocumentAttributeCollection() : base() { }
public DocumentATTRIBUTES this[int index]
{
get
{
return (DocumentATTRIBUTES)this.InnerList[index];
}
}
public void Insert(int index, DocumentATTRIBUTES value)
{
this.InnerList.Insert(index, value);
}
public int Add(DocumentATTRIBUTES value)
{
return (this.InnerList.Add(value));
}
}
However when I try to serialize my object using
XmlSerializer serializer = new XmlSerializer(typeof(DocumentMetaData));
I get the error:
{"Unable to generate a temporary class (result=1).\r\nerror CS0030:
Cannot convert type 'DocumentATTRIBUTES' to 'DocumentAttributeCollection'\r\nerror CS1502: The best overloaded method match for 'DocumentAttributeCollection.Add(DocumentATTRIBUTES)' has some invalid arguments\r\nerror CS1503: Argument '1': cannot convert from 'DocumentAttributeCollection' to 'DocumentATTRIBUTES'\r\n"}
the XSD pertaining to this property is
<xs:complexType>
<xs:sequence>
<xs:element name="ATTRIBUTES" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="author" type="xs:string" minOccurs="0" />
<xs:element name="max_versions" type="xs:string" minOccurs="0" />
<xs:element name="summary" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>