private static Element CloneIconLink(IconStyle.IconLink iconLink) { using (var stream = new MemoryStream()) { var serializer = new Serializer(); if (iconLink.Parent == null) { var parent = new IconStyle { Icon = iconLink, }; serializer.Serialize(parent, stream); parent.Icon = null; // Sets the Icon's Parent property back to null } else { serializer.Serialize(iconLink.Parent, stream); } stream.Position = 0; var parser = new Parser(); parser.Parse(stream, false); var root = (IconStyle)parser.Root; IconStyle.IconLink output = root.Icon; root.Icon = null; // Clear the output's parent return(output); } }
public void TestCloneIcon() { // This is an oddball case because there are two Kml <icon>'s var link = new IconStyle.IconLink(new Uri("link", UriKind.Relative)); var clone = link.Clone(); Assert.That(clone.Href, Is.EqualTo(link.Href)); Assert.That(link.Parent, Is.Null); Assert.That(clone.Parent, Is.Null); IconStyle iconStyle = new IconStyle(); iconStyle.Icon = link; clone = iconStyle.Icon.Clone(); Assert.That(clone.Href, Is.EqualTo(iconStyle.Icon.Href)); Icon icon = new Icon(); icon.Id = "icon"; var iconClone = icon.Clone(); Assert.That(iconClone.Id, Is.EqualTo(icon.Id)); }