/// <summary> /// Sets the value of this <see cref="XAttribute"/>. /// <seealso cref="XElement.SetValue"/> /// <seealso cref="XElement.SetAttributeValue"/> /// <seealso cref="XElement.SetElementValue"/> /// </summary> /// <param name="value"> /// The value to assign to this attribute. The value is converted to its string /// representation and assigned to the <see cref="Value"/> property. /// </param> /// <exception cref="ArgumentNullException"> /// Thrown if the specified value is null. /// </exception> public void SetValue(object value) { if (value == null) { throw new ArgumentNullException("value"); } Value = XContainer.GetStringValue(value); }
private void AddContent(object content) { if (content != null) { XNode n = content as XNode; if (n != null) { this.AddNode(n); } else { string s = content as string; if (s != null) { this.AddString(s); } else { XStreamingElement other = content as XStreamingElement; if (other != null) { this.AddNode(new XElement(other)); } else { object[] objArray = content as object[]; if (objArray != null) { foreach (object obj2 in objArray) { this.AddContent(obj2); } } else { IEnumerable enumerable = content as IEnumerable; if (enumerable != null) { foreach (object obj3 in enumerable) { this.AddContent(obj3); } } else { if (content is XAttribute) { throw new ArgumentException(Res.GetString("Argument_AddAttribute")); } this.AddString(XContainer.GetStringValue(content)); } } } } } } }
private void Write(object content) { if (content == null) { return; } XNode n = content as XNode; if (n != null) { WriteNode(n); return; } string s = content as string; if (s != null) { WriteString(s); return; } XAttribute a = content as XAttribute; if (a != null) { WriteAttribute(a); return; } XStreamingElement x = content as XStreamingElement; if (x != null) { WriteStreamingElement(x); return; } object[] o = content as object[]; if (o != null) { foreach (object obj in o) { Write(obj); } return; } IEnumerable e = content as IEnumerable; if (e != null) { foreach (object obj in e) { Write(obj); } return; } WriteString(XContainer.GetStringValue(content)); }
/// <overloads> /// Initializes a new instance of the <see cref="XAttribute"/> class. /// </overloads> /// <summary> /// Initializes a new instance of the <see cref="XAttribute"/> class from /// the specified name and value. /// </summary> /// <param name="name"> /// The name of the attribute. /// </param> /// <param name="value"> /// The value of the attribute. /// </param> /// <exception cref="ArgumentNullException"> /// Thrown if the passed in name or value are null. /// </exception> public XAttribute(XName name, object value) { ArgumentNullException.ThrowIfNull(name); ArgumentNullException.ThrowIfNull(value); string s = XContainer.GetStringValue(value); ValidateAttribute(name, s); this.name = name; this.value = s; }
private void AddContent(object content) { if (content == null) { return; } XNode n = content as XNode; if (n != null) { AddNode(n); return; } string s = content as string; if (s != null) { AddString(s); return; } XStreamingElement x = content as XStreamingElement; if (x != null) { AddNode(new XElement(x)); return; } object[] o = content as object[]; if (o != null) { foreach (object obj in o) { AddContent(obj); } return; } IEnumerable e = content as IEnumerable; if (e != null) { foreach (object obj in e) { AddContent(obj); } return; } if (content is XAttribute) { throw new ArgumentException(SR.Argument_AddAttribute); } AddString(XContainer.GetStringValue(content)); }
/// <overloads> /// Initializes a new instance of the <see cref="XAttribute"/> class. /// </overloads> /// <summary> /// Initializes a new instance of the <see cref="XAttribute"/> class from /// the specified name and value. /// </summary> /// <param name="name"> /// The name of the attribute. /// </param> /// <param name="value"> /// The value of the attribute. /// </param> /// <exception cref="ArgumentNullException"> /// Thrown if the passed in name or value are null. /// </exception> public XAttribute(XName name, object value) { if (name == null) { throw new ArgumentNullException("name"); } if (value == null) { throw new ArgumentNullException("value"); } string s = XContainer.GetStringValue(value); ValidateAttribute(name, s); this.name = name; this.value = s; }
public void SetElementValue(XName name, object value) { XElement n = base.Element(name); if (value == null) { if (n != null) { base.RemoveNode(n); } } else if (n != null) { n.Value = XContainer.GetStringValue(value); } else { base.AddNode(new XElement(name, XContainer.GetStringValue(value))); } }
public void SetAttributeValue(XName name, object value) { XAttribute a = this.Attribute(name); if (value == null) { if (a != null) { this.RemoveAttribute(a); } } else if (a != null) { a.Value = XContainer.GetStringValue(value); } else { this.AppendAttribute(new XAttribute(name, value)); } }
/// <summary> /// Sets the value of this <see cref="XAttribute"/>. /// <seealso cref="XElement.SetValue"/> /// <seealso cref="XElement.SetAttributeValue"/> /// <seealso cref="XElement.SetElementValue"/> /// </summary> /// <param name="value"> /// The value to assign to this attribute. The value is converted to its string /// representation and assigned to the <see cref="Value"/> property. /// </param> /// <exception cref="ArgumentNullException"> /// Thrown if the specified value is null. /// </exception> public void SetValue(object value) { ArgumentNullException.ThrowIfNull(value); Value = XContainer.GetStringValue(value); }
private void Write(object content) { if (content != null) { XNode n = content as XNode; if (n != null) { this.WriteNode(n); } else { string s = content as string; if (s != null) { this.WriteString(s); } else { XAttribute a = content as XAttribute; if (a != null) { this.WriteAttribute(a); } else { XStreamingElement e = content as XStreamingElement; if (e != null) { this.WriteStreamingElement(e); } else { object[] objArray = content as object[]; if (objArray != null) { foreach (object obj2 in objArray) { this.Write(obj2); } } else { IEnumerable enumerable = content as IEnumerable; if (enumerable != null) { foreach (object obj3 in enumerable) { this.Write(obj3); } } else { this.WriteString(XContainer.GetStringValue(content)); } } } } } } } }