This issue is somewhat related:
Problem with Code Generated by XSD.EXE: Sequence of Elements is Generated as an Array
Basically, I would rather work with an ArrayList in C# code then an array. I have a collection of errors, and I’m writing code to send back additional errors to the already existing collection of errors. Or if I find the first error, I have to instantiate this object, and set the first error of the array. I don’t want to deal with resizing a C# array. It seems like it would be much easier to just add to an ArrayList.
I think question I referenced above was sort of asking the same thing, but in my case, I do have a complex type, not a simple one.
My schema has a field called Status which contains this:
<xs:element minOccurs="0" name="Errors">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="Error">
<xs:complexType>
<xs:sequence>
<xs:element name="ErrorNumber" type="xs:string" />
<xs:element name="ErrorMessage" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
I use xsd.exe to generate a C# class.
I could have made “Error” a separate schema, and referenced it (schema create with BizTalk 2006/R2), if that would make any difference in the C# generated.
The generated C# class looks like this:
private StatusError[] errorsField;
[System.Xml.Serialization.XmlArrayAttribute(Form= System.Xml.Schema.XmlSchemaForm.Unqualified)]
[System.Xml.Serialization.XmlArrayItemAttribute(“Error”,
Form =
System.Xml.Schema.XmlSchemaForm.Unqualified,
IsNullable = false)]
public StatusError[] Errors
{
get
{
return this.errorsField;
}
set
{
this.errorsField = value;
}
} }[System.CodeDom.Compiler.GeneratedCodeAttribute(“xsd”,
“2.0.50727.1432”)]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(“code”)]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType
= true, Namespace = “https://firstrepublic.com/EagleConnect/Status/“)]
public partial class StatusError {private string errorNumberField; private string errorMessageField; /// <remarks/> [System.Xml.Serialization.XmlElementAttribute(Form= System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string ErrorNumber
{
get
{
return this.errorNumberField;
}
set
{
this.errorNumberField = value;
}
}
Well, I had to continue, so I used Array.Resize. Came up with a method to look at the array, if it’s not there add it, if it was there add to it, etc… An arrayList would have been easier and quicker.