protected void WritePotentiallyReferencingElement(string n, string ns, object o, Type ambientType, bool suppressReference, bool isNullable)
{
if (o == null)
{
if (isNullable) WriteNullTagEncoded(n, ns);
return;
}
Type t = o.GetType();
if (t.GetTypeCode() == TypeCode.Object && !(o is Guid) && (t != typeof(XmlQualifiedName)) && !(o is XmlNode[]) && (t != typeof(byte[])))
{
if ((suppressReference || _soap12) && !IsIdDefined(o))
{
WriteReferencedElement(n, ns, o, ambientType);
}
else
{
if (n == null)
{
TypeEntry entry = GetTypeEntry(t);
WriteReferencingElement(entry.typeName, entry.typeNs, o, isNullable);
}
else
WriteReferencingElement(n, ns, o, isNullable);
}
}
else
{
// Enums always write xsi:type, so don't write it again here.
bool needXsiType = t != ambientType && !t.GetTypeInfo().IsEnum;
TypeEntry entry = GetTypeEntry(t);
if (entry != null)
{
if (n == null)
WriteStartElement(entry.typeName, entry.typeNs, null, true);
else
WriteStartElement(n, ns, null, true);
if (needXsiType) WriteXsiType(entry.typeName, entry.typeNs);
entry.callback(o);
_w.WriteEndElement();
}
else
{
WriteTypedPrimitive(n, ns, o, needXsiType);
}
}
}