public static XElement ToXElement(Library library) { Validator.IsNotNull(library, "library"); var attributes = new XObject[] { new XAttribute("v", library.Version), new XAttribute("st", library.SourceType) }; IEnumerable<XObject> items = library.Items.Select(item => ToXElement(item)).Cast<XObject>(); IEnumerable<XObject> objects = attributes.Concat(items); return new XElement("l", objects); }