我有一个带有多个继承级别的模型的XML模式,其中A和B是抽象类型:
+----+ +----+ +---+
| A* |<-+--| B* |<-+--| D |
+----+ | +----+ | +---+
| +---+ | +---+
+--| C | +--| E |
+---+ +---+
架构如下所示:
<element name="Thing">
<complexType>
<sequence>
<element ref="app:number"/>
</sequence>
</complexType>
</element>
<element name="number" type="app:numberType" abstract="true"/>
<complexType name="numberType" abstract="true"/>
<element name="madeUpNumber" type="app:madeUpNumberType" substitutionGroup="app:number"/>
<complexType name="madeUpNumberType">
<complexContent>
<extension base="app:numberType">
<sequence>
<element name="value" type="string"/>
</sequence>
</extension>
</complexContent>
</complexType>
<element name="realNumber" type="app:realNumberType" substitutionGroup="app:number" abstract="true"/>
<complexType name="realNumberType" abstract="true">
<complexContent>
<extension base="app:numberType"/>
</complexContent>
</complexType>
<element name="evenNumber" type="app:evenNumberType" substitutionGroup="app:realNumber"/>
<complexType name="evenNumberType">
<complexContent>
<extension base="app:realNumberType">
<sequence>
<element name="value" type="int"/>
</sequence>
</extension>
</complexContent>
</complexType>
<element name="oddNumber" type="app:oddNumberType" substitutionGroup="app:realNumber"/>
<complexType name="oddNumberType">
<complexContent>
<extension base="app:realNumberType">
<sequence>
<element name="value" type="int"/>
</sequence>
</extension>
</complexContent>
</complexType>
我尝试使用Visual Studio Express 2012生成客户端C#代码,但这就是我得到的:
public partial class Thing : object, System.ComponentModel.INotifyPropertyChanged {
private madeUpNumberType itemField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("madeUpNumber", Order=0)]
public madeUpNumberType Item {
get {
return this.itemField;
}
set {
this.itemField = value;
this.RaisePropertyChanged("Item");
}
}
...
由于madeUpNumberType
只收到Thing
,我可以收到此回复
<Thing>
<madeUpNumber>
<value>Infinity!</value>
</madeUpNumber>
</Thing>
但不是这个
<Thing>
<evenNumber>
<value>8</value>
</evenNumber>
</Thing>
除了在生成的Reference.cs中手动拨动外,我能做些什么吗?