Created
April 21, 2016 15:25
-
-
Save kjnilsson/37f0f8dc2d31baff42f1ec1e100893a7 to your computer and use it in GitHub Desktop.
useful active patterns for link2xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let xname s = XName.Get s | |
let xn s = XName.Get s | |
let xe n (v: obj) = new XElement(xn (msbuildns + n), v) | |
let xa n (v: obj) = new XAttribute(xn n, v) | |
let (|Head|_|) = | |
Seq.tryFind (fun _ -> true) | |
let (|Value|) (xe: XElement) = | |
xe.Value | |
let (|Guid|_|) s = | |
match Guid.TryParse s with | |
| true, g -> Some g | |
| _ -> None | |
let (|Descendants|_|) name (xe : XElement) = | |
match xe.Descendants (xn (msbuildns + name)) with | |
| null -> None | |
| desc when not (Seq.isEmpty desc) -> | |
Some (desc |> Seq.toList) | |
| _ -> None | |
let (|Descendant|_|) name (xe : XElement) = | |
match xe.Descendants (xn (msbuildns + name)) with | |
| null -> None | |
| Head h -> Some h | |
| _ -> None | |
let (|Element|_|) name (xe : XElement) = | |
match xe.Element (xn (msbuildns + name)) with | |
| null -> None | |
| e -> Some e | |
let (|Attribute|_|) name (xe : XElement) = | |
match xe.Attribute (xn name) with | |
| null -> None | |
| a -> Some a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment