2010-10-14 63 views

回答

0

不,沒有。我結束了手動。幸運的是,我使用F#,所以很容易。如果你看看代碼來做到這一點在JavaScript中,它做到了類似的輕鬆(不需要反思)。是

let applyFixups (json : JSON_RPC<JSONArrayList<_>>) = 
    let applyFixup (items : array<_>) (fixup : array<array<obj>>) = 
     let sourceIdx = fixup.[1].[1] :?> int 
     let destIdx = fixup.[0].[1] :?> int 
     let sourceProp = fixup.[1].[2] :?> string 
     let destProp = fixup.[0].[2] :?> string 
     let value = items.[sourceIdx].GetType().GetProperty(sourceProp).GetGetMethod().Invoke(items.[sourceIdx], Array.empty) 
     items.[destIdx].GetType().GetProperty(destProp).GetSetMethod().Invoke(items.[destIdx], [|value|]) |> ignore 
     () 
    if json.fixups <> null then 
     let fu = json.fixups 
     Seq.iter (applyFixup json.result.list) fu 
    () 

類型此如下...

[<DataContract>] 
type JSON_RPC<'T> = { 
    [<DataMember>] 
    mutable fixups : array<array<array<obj>>> 
    [<DataMember>] 
    mutable id : int 
    [<DataMember>] 
    mutable result : 'T 
} 

[<DataContract>] 
type JSONArrayList<'T> = { 
    [<DataMember>] 
    mutable javaClass: string 
    [<DataMember>] 
    mutable list: 'T array 
}