2017-05-23 4 views
0

私のxsd.exe - 生成されたクラスは、私がそれらをしたいと正確にシリアライズしていません。 InterestInPropertyをシリアライズ版に表示する方法を教えてもらえますか?オーバーライドされたメンバーが正しくシリアル化されていません

ここに投稿するには、生成されたクラスが長すぎます(14,000行のC#)がありますが、関連する抜粋を表示しようとします。参考のために、here is the full schema

私は1つのチャンクが、これにシリアライズしたい:のはInterestInPropertyを直列化するためのソリューションがReasonForに適用されると仮定しましょう当分の間

<FullRegistered ValSubType="Standard"> 
    ... 
</FullRegistered> 

<FullRegistered ValSubType="Standard" ReasonFor="FairMarketValue" InterestInProperty="FeeSimpleInPossession"> 
    ... 
</FullRegistered> 

が、それは実際にこれに直列化です。

ここFullRegistered項目が含まれているValuationTypeクラスだ:

/// <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, 
} 
+0

プライベート変数はシリアル化されません。公開する。 – jdweng

+0

@jdweng、プライベートフィールドは実際には 'public FullRegisteredInterestInProperty InterestInProperty'のようなパブリックプロパティのフィールドをバッキングしています – OutstandingBill

答えて

1

あなたの避難所'笑どのようにプロパティを設定しているのですか?私は、シリアル化しない2つのプロパティに関連するプロパティーを無視したと推測します。

the documentationパー

別のオプションは、XmlSerializerをによって認識ブールフィールドを作成するために特殊なパターンを使用して、フィールドにXmlIgnoreAttributeを適用することです。パターンはpropertyName指定の形で作成されます。たとえば、 "MyFirstName"という名前のフィールドがある場合は、 "MyFirstNameSpecified"という名前のフィールドを作成し、XmlSerializerに "MyFirstName"という名前のXML要素を生成するかどうかを指示します。

あなたはInterestInPropertyReasonForをシリアル化したいのであれば、あなたはtrueに生成InterestInPropertySpecifiedReasonForSpecifiedプロパティを設定する必要があります。

+0

私はxxxSpecifiedを設定していなかったという仮定は正しいものでした。そして今、私はうまくいきます。どうもありがとう。 – OutstandingBill

関連する問題