Title: Refactored condition checks in XmlFormatter2.cs
x) This change also includes a check on the writer's state before deciding whether to write elements, improving robustness of the serialization process.
This commit is contained in:
parent
b66bc4e5ed
commit
d58fb58b3a
@ -1139,12 +1139,21 @@ namespace lib
|
|||||||
|
|
||||||
if( typeCode != TypeCode.Object )
|
if( typeCode != TypeCode.Object )
|
||||||
{
|
{
|
||||||
if( _cfg.POD == POD.Elements || forceType )
|
bool writeELements = _cfg.POD == POD.Elements || forceType;
|
||||||
|
|
||||||
|
if( !writeELements && writer is XmlTextWriter textWriter )
|
||||||
|
{
|
||||||
|
var writeState = textWriter.WriteState;
|
||||||
|
|
||||||
|
writeELements = writeState != WriteState.Element;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( writeELements )
|
||||||
writer.WriteStartElement( name );
|
writer.WriteStartElement( name );
|
||||||
|
|
||||||
SerializeConcrete( writer, mi, root, name, forceType );
|
SerializeConcrete( writer, mi, root, name, forceType );
|
||||||
|
|
||||||
if( _cfg.POD == POD.Elements || forceType )
|
if( writeELements )
|
||||||
writer.WriteEndElement();
|
writer.WriteEndElement();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user