我嘗試將C#代碼轉換爲F#。
但faild。
這是來自bolgpost的C#代碼LINQ Reduces Line Counts and Makes Code 「Pop」如何在F#中將obj轉儲到xml#
這是關於FP。
我把它轉變爲
#r "System.Core.dll"
#r "System.Xml.Linq.dll"
open System
open System.Reflection
open System.Collections
open System.Collections.Generic
open System.Xml.Linq
let (|V|S|A|O|) o =
if o.GetType().IsValueType then V
elif o.GetType()=typeof<string> then S
elif o.GetType().IsArray then A
else O
let rec obj2xml r o =
match o with
| V | S -> new XElement(r, o)
| A -> o |> Array.map (fun z -> obj2xml r z)
| O -> new XElement(r, o.GetType().GetProperties() |> Array.map (fun z -> obj2xml (z.Name) (z.GetValue(o, null))))
| V | S - > new XElement(r,o) return a XElement
| A - > o |> Array.map(fun z - > obj2xml r z) return a Array
我搞不明白了!
我還沒有得到它的遵守!
請幫幫我!
「它不起作用」不會讓你對SO非常感興趣。 – 2010-06-15 10:32:52
「不起作用」是什麼意思?你的意思是它的功能不正確,或者它不能編譯/編譯? – ChrisBD 2010-06-15 10:35:11