4
我是一個F#n00b總數,所以我希望我給你足夠的信息。我創建了一個名爲record的類。我用數據庫中的數據創建了這個類的幾個實例。然後我將每條記錄添加到記錄列表中。我想用這些記錄製作一個xml文檔。用F#編碼的XML序列號
//this is the record data type i created. I also created a sender and recipient data
//type but those are probably not neccessary to understand the issue
type record(id:int, sender:sender, ?recipients: recipient list) =
let mutable id: int = id
let mutable typ = "Message"
let mutable creation = creation()
let mutable sender = sender
let mutable recipients = recipients
[<XmlIgnore()>]
[<XmlArrayAttribute("recipients")>]
[<XmlArrayItem(typeof<recipient>, ElementName = "recipient")>]
member this.Recipients with get() = recipients and set v = recipients <- v
public new() =
record(12180, sender(12180,"Joe","Plumber","[email protected]"), list.Empty)
[<XmlElement("id")>]
member this.Id with get() = id and set v = id <- v
[<XmlElement("creation")>]
member this.Creation with get() = creation and set v = creation <- v
[<XmlElement("sender")>]
member this.Sender with get() = sender and set v = sender <- v
//i later call this:
let xmlSerializer = XmlSerializer(typeof<record list>)
我然後在運行時得到這個錯誤消息:
有反射型 'Microsoft.FSharp.Collections.FSharpList`1 [XXXX.Compliance.YYYYY.record]' 的誤差。 // x's和y用於保護無辜者。
我認爲你是對的。我改變了所有的數組而不是列表。似乎已經做到了。 – Ramy 2010-06-23 18:33:01