读书人

关于对象序列化的一个有关问题,

发布时间: 2012-01-16 23:36:51 作者: rapoo

关于对象序列化的一个问题,急..
有一个对象
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://marketing.ews.yahooapis.com/V4")]
public partial class TargetingAttribute {

private TargetingAttributeDescriptor[] targetsField;

/// <remarks/>
[System.Xml.Serialization.XmlArrayAttribute(IsNullable=true)]
public TargetingAttributeDescriptor[] targets {
get {
return this.targetsField;
}
set {
this.targetsField = value;
}
}
}

子对象
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://marketing.ews.yahooapis.com/V4")]
public partial class TargetingAttributeDescriptor {

private long idField;

private bool idFieldSpecified;

private System.Nullable<TargetingAttributeType> typeField;

private bool typeFieldSpecified;

/// <remarks/>
public long ID {
get {
return this.idField;
}
set {
this.idField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool IDSpecified {
get {
return this.idFieldSpecified;
}
set {
this.idFieldSpecified = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
public System.Nullable<TargetingAttributeType> type {
get {
return this.typeField;
}
set {
this.typeField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool typeSpecified {
get {
return this.typeFieldSpecified;
}
set {
this.typeFieldSpecified = value;
}
}
}

我将TargetingAttribute 进行xml序列化后,得到的结果是
<?xml version="1.0" encoding="utf-16"?>
<TargetingAttribute xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<targets xmlns="http://marketing.ews.yahooapis.com/V4">
<TargetingAttributeDescriptor />
</targets>
</TargetingAttribute>

我确定TargetingAttributeDescriptor 对象是有值得,但是序列化出来的TargetingAttributeDescriptor 对象的属性都没了..



请问是哪个环节出问题了呢...谢谢!


[解决办法]

C# code
    [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]    [System.SerializableAttribute()]    [System.Diagnostics.DebuggerStepThroughAttribute()]    [System.ComponentModel.DesignerCategoryAttribute("code")]    [System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://marketing.ews.yahooapis.com/V4")]    public partial class TargetingAttributeDescriptor    {        private long idField;        private bool idFieldSpecified;        private System.Nullable<TargetingAttributeType> typeField;        private bool typeFieldSpecified;        /// <remarks/>         [XmlAttribute()]        public long TargetingAttributeID  //你这里原来写的ID,应该是和XML里的某个元素重复了,无法显示。下面的Type也一样,我改成            {                  //TargetingAttributeType            get            {                return this.idField;            }            set            {                this.idField = value;            }        }        /// <remarks/>         [XmlAttribute()]        public bool IDSpecified        {            get.Calculate(); 

读书人网 >C#

热点推荐