WriteElementValue method

void WriteElementValue(
  1. XmlNamespace xmlNamespace,
  2. String? localName,
  3. String? displayName,
  4. Object? value,
)
Writes the element value. The XML namespace. The local name of the element. The name that should appear in the exception message when the value can not be serialized. The value.

Implementation

void WriteElementValue(XmlNamespace xmlNamespace, String? localName,
    String? displayName, Object? value) {
  String? stringValue;
  OutParam<String> strOut = new OutParam<String>();
  if (this.TryConvertObjectToString(value, strOut)) {
    stringValue = strOut.param;
    //  PS # 205106: The code here used to check IsNullOrEmpty on stringValue instead of just null.
    //  Unfortunately, that meant that if someone really needed to update a String property to be the

    //  an error on the server because an update is required to have a single sub-element that is the
    //  value to update.  So we need to allow an empty String to create an empty element (like <Value />).
    //  Note that changing this check to just check for null is fine, because the other types that get
    //  converted by TryConvertObjectToString() won't return an empty String if the conversion is
    //  successful (for instance, converting an integer to a String won't return an empty String - it'll
    //  always return the stringized integer).
    if (stringValue != null) {
      this.WriteStartElement(xmlNamespace, localName);
      this.WriteValue(stringValue, displayName);
      this.WriteEndElement();
    }
  } else {
    throw new ServiceXmlSerializationException(
        "ElementValueCannotBeSerialized(${value.runtimeType}, $localName)");
  }
}