Also, what modules need to be included?

See the docs for XDocument/...:

Namespace: <mshelp:link tabindex="0" keywords="N:System.Xml.Linq">System.Xml.Linq</mshelp:link>
Assembly:

System.Xml.Linq (in System.Xml.Linq.dll)

My try on the formatting:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#r "System.Xml.Linq"

open System.Xml.Linq

// http://cs.hubfs.net/forums/thread/11005.aspx
let inline (!>) arg = ( ^a : (static member op_Implicit : ^b -> ^a) arg)

type Segment( id:int ) =
    member x.Id = id
    
    override x.ToString() =
        let root =
            XDocument(
                XDeclaration("1.0", "utf-8", "yes"),
                [| box <| XElement(!> "Segment", 
                    XElement(!> "id", x.Id))
                |]
            )
        root.ToString()

Looks like

1
[| x :> T |]

isn't valid, not sure why...

error FS0010: Unexpected symbol ':>'" " in interaction. Expected '|]' or other token.

By on 7/23/2009 6:27 AM ()

That still seems like a verbose transcription of what I would write in C#. I was thinking more along the lines of an f# specific library that handles the casting and the generation of single element arrays.

If nothing like that exists, it's not too difficult to write it. But, looking through the tutorials, it seems like at one time there was at one time a ``Microsoft.FSharp.Xml.Linq'' namespace.

By on 7/24/2009 4:59 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper