XSD工具追加"指定"某些性能/领域产生的C#代码时 [英] XSD tool appends "Specified" to certain properties/fields when generating C# code
问题描述
我的XSD发生器我真的不能解释一个奇怪的行为。我有一个这样的XSD:
I got a strange behaviour with the XSD generator I can't really explain. I got an XSD like this:
<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>
它是从CoreObject来源:
it is derived from 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>
这是XSD的只是一小部分,还有很多更复杂的类型。
This is just a small part of the XSD, there are a lot more complex types.
所以,当我产生类似的这,我得到一个生成的类有两个属性(除5这是我所期望的):
So when I generate the classes similar to this, I get a generated class which has two more properties (in addition to the 5 which I would expect):
public bool MinDuration_100msSpecified
以及
public bool StageOnDemandSpecified
所以,原创属性指定被追加现在的类型是布尔。
谁能解释这是为什么?
So to the "original" property "Specified" was appended and the type is now bool. Can anyone explain why this is so?
推荐答案
的布尔
属性是指相关属性应序列化。
the bool
attribute means the related attribute should be serialized.
如:
如果在布尔
MinDuration_100msSpecified
设置为假
,并设置在 MinDuration_100ms
是 300
,当你使用的XmlSerializer
来序列化对象时,<code> MinDuration_100ms 属性不会被序列化。
If the bool
MinDuration_100msSpecified
is set to false
, and you set the MinDuration_100ms
to be 300
, when you use XmlSerializer
to serialize the object, the MinDuration_100ms
attribute won't be serialized.
此功能可序列化的XML文件保存到是最小的。
This feature can save the serialized xml file to be minimal.
这篇关于XSD工具追加"指定"某些性能/领域产生的C#代码时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!