2012-10-17 13 views
1

如果我有一個繼承自通用列表的基類,並且派生類需要使用列表條目的自定義名稱進行序列化,那麼我如何輸入正確的serializartion屬性和/或引用基地清單?繼承列表的自定義序列化

Public MustInherit Class SpecialList(Of T) 
    Inherits List(Of T) 
    'Other methods here 
End Class 

Public Class Cache 
    Inherits SpecialList(Of CacheEntry) 

    <XmlElementAttribute("CustomName")> _ 
    Public Property Entries() As List(Of CacheEntry) 
     Get 
     Return ??? 
     End Get 
     Set(value As List(Of CacheEntry)) 
     ??? = value 
     End Set 
    End Property 
End Class 

這實際上可能沒有重寫基類方法,編寫自定義序列化或實現IXmlSerializable?

我期待得到輸出XML是這樣的:

<cache> 
    <customname></customname> 
    <customname></customname> 
</cache> 
+0

你試過了嗎? –

+0

是的,看到上面的代碼,它不會編譯 –

回答

0

添加XmlRootAttributeCacheEntry

<XmlRootAttribute(ElementName:="customname")> 
Public Class CacheEntry 

作爲一個方面的問題,如果從ListCache繼承(通過SpecialList)那麼爲什麼你有一個Entries屬性也是List