Der*_*Ape 12 c# code-generation xsd.exe
我对XSD生成器有一种奇怪的行为,我无法解释.我得到了这样的XSD:
<xs:complexType name="StageSequenceElement" mixed="false">
<xs:complexContent>
<xs:extension base="CoreObject">
<xs:sequence>
<xs:element name="Description" type="xs:string" minOccurs="0">
<xs:annotation>
<xs:documentation>Some Doc</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="StageRef" type="ObjectReference">
<xs:annotation>
<xs:documentation>...</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="MinDuration_100ms" type="xs:int" nillable="true" minOccurs="0">
<xs:annotation>
<xs:documentation>...</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="MaxDuration_100ms" type="xs:int" nillable="true">
<xs:annotation>
<xs:documentation>...</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="StageOnDemand" type="xs:boolean" nillable="true" minOccurs="0">
<xs:annotation>
<xs:documentation>...</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
Run Code Online (Sandbox Code Playgroud)
它源自CoreObject:
<xs:complexType name="CoreObject">
<xs:sequence>
<xs:element name="No" type="xs:int">
<xs:annotation>
<xs:documentation>...</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
Run Code Online (Sandbox Code Playgroud)
这只是XSD的一小部分,还有更复杂的类型.
因此,当我生成类似于此的类时,我得到一个生成的类,它有两个属性(除了我期望的5):
public bool MinDuration_100msSpecified
Run Code Online (Sandbox Code Playgroud)
和
public bool StageOnDemandSpecified
Run Code Online (Sandbox Code Playgroud)
所以对于"原始"属性,附加了"Specified",类型现在是bool.任何人都可以解释为什么会这样吗?
小智 11
该bool属性是指相关属性应该被序列化.
例如
如果bool MinDuration_100msSpecified设置为false,并且您将其MinDuration_100ms设置为300,则在使用XmlSerializer序列化对象时,该MinDuration_100ms属性将不会被序列化.
此功能可以将序列化的xml文件保存为最小.