public new XmlElementWithContent ToImmutable() { var children = this.children.IsDefined ? (this.children.Value != null ? this.children.Value.ToImmutable() : null) : this.immutable.Children; return(this.immutable = this.immutable.With( ImmutableObjectGraph.Optional.For(this.LocalName), ImmutableObjectGraph.Optional.For(this.NamespaceName), ImmutableObjectGraph.Optional.For(children), ImmutableObjectGraph.Optional.For(this.Content))); }
public virtual XmlElementWithContent ToXmlElementWithContent( ImmutableObjectGraph.Optional <System.String> content = default(ImmutableObjectGraph.Optional <System.String>)) { XmlElementWithContent that = this as XmlElementWithContent; if (that != null && this.GetType().IsEquivalentTo(typeof(XmlElementWithContent))) { if ((!content.IsDefined || content.Value == that.Content)) { return(that); } } return(XmlElementWithContent.Create( localName: this.LocalName, namespaceName: this.NamespaceName, children: this.Children, content: content)); }
public void TypeConversion() { XmlElement ordinaryElement = XmlElement.Create("TagName"); Assert.IsNotType(typeof(XmlElementWithContent), ordinaryElement); // Switch to derived type, without extra data. XmlElementWithContent elementWithContent = ordinaryElement.ToXmlElementWithContent(); Assert.Equal(ordinaryElement.LocalName, elementWithContent.LocalName); // Switch to derived type, including extra data. elementWithContent = ordinaryElement.ToXmlElementWithContent("SomeContent"); Assert.Equal(ordinaryElement.LocalName, elementWithContent.LocalName); Assert.Equal("SomeContent", elementWithContent.Content); // Switch back to base type. XmlElement backAgain = elementWithContent.ToXmlElement(); Assert.IsNotType(typeof(XmlElementWithContent), backAgain); Assert.Equal(ordinaryElement.LocalName, backAgain.LocalName); }
internal Builder(XmlElementWithContent immutable) : base(immutable) { this.immutable = immutable; this.content = immutable.Content; }