Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 重写的成员未正确序列化_C#_Xml_Xsd.exe - Fatal编程技术网

C# 重写的成员未正确序列化

C# 重写的成员未正确序列化,c#,xml,xsd.exe,C#,Xml,Xsd.exe,我的xsd.exe-生成的类没有按照我希望的方式进行序列化。谁能告诉我如何使InterestInProperty显示在序列化版本中 生成的类太长(14000行C#),无法在这里发布,但我将尝试显示相关摘录。供参考 我想要一个块序列化到这个: <FullRegistered ValSubType="Standard" ReasonFor="FairMarketValue" InterestInProperty="FeeSimpleInPossession"> ... </

我的
xsd.exe
-生成的类没有按照我希望的方式进行序列化。谁能告诉我如何使
InterestInProperty
显示在序列化版本中

生成的类太长(14000行C#),无法在这里发布,但我将尝试显示相关摘录。供参考

我想要一个块序列化到这个:

<FullRegistered ValSubType="Standard" ReasonFor="FairMarketValue" InterestInProperty="FeeSimpleInPossession">
    ...
</FullRegistered>
以下是
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; }
    }

}
以及
fullRegisteredEnterestinProperty
enum:

[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,
}

您还没有展示如何填充属性,但我猜您忽略了与未序列化的两个属性相关的
xxxsspecified
属性

Per:

另一个选项是使用特殊模式创建XmlSerializer识别的布尔字段,并将
XmlIgnoreAttribute
应用于该字段。模式以propertyNameSpecified的形式创建。例如,如果有一个名为“MyFirstName”的字段,您还将创建一个名为“MyFirstNameSpecified”的字段,该字段指示XmlSerializer是否生成名为“MyFirstName”的XML元素


因此,如果希望序列化
InterestInProperty
ReasonFor
,则需要将生成的
interestinPropertySspecified
ReasonForSpecified
属性设置为
true

私有变量将不会序列化。然后将其公开。@jdweng,私有字段实际上是公共属性的支持字段,例如
public FullRegisteredInterestInProperty InterestInProperty
您认为我没有设置xxxsspecified是正确的。现在我是了,它很好地连载了。非常感谢。
[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; }
    }

}
[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,
}