I'm programatically generating an XSD file from some C# classes using XmlReflectionImporter. My goal is to generate a schema representing XML similar to the following:
<MyCriteriaList MinimumMatches="2">
<Criterion>First Criterion</Criterion>
<Criterion>Second ...</Criterion>
...
</MyCriteriaList>
So, an example XSD representing this would be:
<xs:element name="MyCriteriaList" type="ArrayOfCriterion" />
...
<xs:complexType name="ArrayOfCriterium">
<xs:sequence>
<xs:element name="Criterion" type="xs:string" />
</xs:sequence>
<xs:attribute name="MinimumMatches" type="xs:integer" />
</xs:complexType>
The class that would represent the array of criterion:
public class Criteria : IList<Criterion>
{
[XmlAttribute]
public int MinimumMatches { get; set; }
// IList implementation...
}
However, this generates the following XSD:
<xs:complexType name="ArrayOfCriterion">
<xs:sequence>
<xs:element name="Criterion" type="xs:string" />
</xs:sequence>
</xs:complexType>
The property MinimumMatches is ignored completely and not added as an attribute to ArrayOfCriterion.
It's as if the XmlReflectionImporter (or possibly the XmlSchemaExporter which is using the result of the importer) is detecting Criteria is an implementation of IList and deciding it's a simple array, completely discarding any properties that have been added over and above the interface implementation.
Any tips greatly appreciated.
Regards,
Steve.