Выпуск сериализации XML из базового класса в производный класс - PullRequest
1 голос
/ 10 августа 2011

У меня проблема с сериализацией производного класса из массива типа базового класса.Он успешно распознает производный класс при сериализации, поскольку имена сериализованных элементов отражают производный класс, однако свойства, уникальные для производного класса, не сериализуются с объектом.

Базовый класс:

[System.Xml.Serialization.XmlIncludeAttribute(typeof(ContactsFolderType))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(CalendarFolderType))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(FolderType))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(TasksFolderType))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(SearchFolderType))]
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://schemas.microsoft.com/exchange/services/2006/types")]
public abstract partial class BaseFolderType
{

    private FolderIdType folderIdField;

    private FolderIdType parentFolderIdField;

    private string folderClassField;

    private string displayNameField;

    private int totalCountField;

    private bool totalCountFieldSpecified;

    private int childFolderCountField;

    private bool childFolderCountFieldSpecified;

    private ExtendedPropertyType[] extendedPropertyField;

    private ManagedFolderInformationType managedFolderInformationField;

    private EffectiveRightsType effectiveRightsField;

    /// <remarks/>
    public FolderIdType FolderId
    {
        get
        {
            return this.folderIdField;
        }
        set
        {
            this.folderIdField = value;
        }
    }

    /// <remarks/>
    public FolderIdType ParentFolderId
    {
        get
        {
            return this.parentFolderIdField;
        }
        set
        {
            this.parentFolderIdField = value;
        }
    }

    /// <remarks/>
    public string FolderClass
    {
        get
        {
            return this.folderClassField;
        }
        set
        {
            this.folderClassField = value;
        }
    }

    /// <remarks/>
    public string DisplayName
    {
        get
        {
            return this.displayNameField;
        }
        set
        {
            this.displayNameField = value;
        }
    }

    /// <remarks/>
    public int TotalCount
    {
        get
        {
            return this.totalCountField;
        }
        set
        {
            this.totalCountField = value;
        }
    }

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

    /// <remarks/>
    public int ChildFolderCount
    {
        get
        {
            return this.childFolderCountField;
        }
        set
        {
            this.childFolderCountField = value;
        }
    }

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

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("ExtendedProperty")]
    public ExtendedPropertyType[] ExtendedProperty
    {
        get
        {
            return this.extendedPropertyField;
        }
        set
        {
            this.extendedPropertyField = value;
        }
    }

    /// <remarks/>
    public ManagedFolderInformationType ManagedFolderInformation
    {
        get
        {
            return this.managedFolderInformationField;
        }
        set
        {
            this.managedFolderInformationField = value;
        }
    }

    /// <remarks/>
    public EffectiveRightsType EffectiveRights
    {
        get
        {
            return this.effectiveRightsField;
        }
        set
        {
            this.effectiveRightsField = value;
        }
    }
}

Производный класс:

[System.Xml.Serialization.XmlIncludeAttribute(typeof(TasksFolderType))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(SearchFolderType))]
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://schemas.microsoft.com/exchange/services/2006/types")]
public partial class FolderType : BaseFolderType
{

    private PermissionSetType permissionSetField;

    private int unreadCountField;

    private bool unreadCountFieldSpecified;

    /// <remarks/>
    public PermissionSetType PermissionSet
    {
        get
        {
            return this.permissionSetField;
        }
        set
        {
            this.permissionSetField = value;
        }
    }

    /// <remarks/>
    public int UnreadCount
    {
        get
        {
            return this.unreadCountField;
        }
        set
        {
            this.unreadCountField = value;
        }
    }

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

При добавлении этого класса в массив BaseFolderType сериализованные элементы будут возвращать

<Folder>
<FolderId/>
<DisplayName/>
...
 </Folder>
All the base properties but none of the derived ones.

Я что-то упустил с моей настройкой атрибута xml, чтобы вызватьэто?

1 Ответ

0 голосов
/ 10 августа 2011

Пожалуйста, посмотрите на эту статью. Я считаю, что это отвечает на ваш вопрос:

http://msdn.microsoft.com/en-us/library/aa302290.aspx

...