【发布时间】:2017-05-23 03:15:21
【问题描述】:
我的xsd.exe 生成的类并没有完全按照我想要的方式进行序列化。谁能告诉我如何让InterestInProperty 出现在序列化版本中?
生成的类太长(14,000 行 C#)无法在此处发布,但我会尝试显示相关的摘录。供参考,here is the full schema。
我想要一个块序列化到这个:
<FullRegistered ValSubType="Standard" ReasonFor="FairMarketValue" InterestInProperty="FeeSimpleInPossession">
...
</FullRegistered>
但它实际上是序列化到这个:
<FullRegistered ValSubType="Standard">
...
</FullRegistered>
暂时让我们假设序列化InterestInProperty 的解决方案将适用于ReasonFor。
这是 ValuationType 类,其中包含 FullRegistered 项:
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1055.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
public partial class ValuationType
{
private Identifier[] identifierField;
private object itemField;
[System.Xml.Serialization.XmlElementAttribute("Identifier")]
public Identifier[] Identifier
{
get { return this.identifierField; }
set { this.identifierField = value; }
}
[System.Xml.Serialization.XmlElementAttribute("Costing", typeof (Costing))]
[System.Xml.Serialization.XmlElementAttribute("FullRegistered", typeof (FullRegistered))]
[System.Xml.Serialization.XmlElementAttribute("ProgressInspection", typeof (ProgressInspection))]
[System.Xml.Serialization.XmlElementAttribute("RestrictedAccessAssessment", typeof (RestrictedAccessAssessment))]
[System.Xml.Serialization.XmlElementAttribute("WorkFlow", typeof (WorkFlow))]
public object Item
{
get { return this.itemField; }
set { this.itemField = value; }
}
}
这是FullRegistered的简略定义:
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1055.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
public partial class FullRegistered
{
private FullRegisteredInterestInProperty interestInPropertyField;
private bool interestInPropertyFieldSpecified;
private FullRegisteredValSubType valSubTypeField;
private FullRegisteredReasonFor reasonForField;
private bool reasonForFieldSpecified;
[System.Xml.Serialization.XmlAttributeAttribute()]
public FullRegisteredInterestInProperty InterestInProperty
{
get { return this.interestInPropertyField; }
set { this.interestInPropertyField = value; }
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool InterestInPropertySpecified
{
get { return this.interestInPropertyFieldSpecified; }
set { this.interestInPropertyFieldSpecified = value; }
}
[System.Xml.Serialization.XmlAttributeAttribute()]
public FullRegisteredValSubType ValSubType
{
get { return this.valSubTypeField; }
set { this.valSubTypeField = value; }
}
[System.Xml.Serialization.XmlAttributeAttribute()]
public FullRegisteredReasonFor ReasonFor
{
get { return this.reasonForField; }
set { this.reasonForField = value; }
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool ReasonForSpecified
{
get { return this.reasonForFieldSpecified; }
set { this.reasonForFieldSpecified = value; }
}
}
还有FullRegisteredInterestInProperty 枚举:
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1055.0")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public enum FullRegisteredInterestInProperty
{
CrownLeasehold,
FeeSimpleInPossession,
ACTLeasehold,
LeaseholdInterest,
Lessors,
Lessees,
SharesInCompany,
SubjectToLongTermLease,
Timeshare,
UnitsInTrust,
Other,
}
【问题讨论】:
-
私有变量不会序列化。然后公开。
-
@jdweng,私有字段实际上是公共属性的支持字段,例如
public FullRegisteredInterestInProperty InterestInProperty