Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit e91a95d

Browse files
authored
Improvements on ReflectionXmlSerializationWriter. (#19027)
* Improvements on ReflectionXmlSerializationWriter. * One minor change.
1 parent d1d504b commit e91a95d

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/System.Private.Xml/src/System/Xml/Serialization/ReflectionXmlSerializationWriter.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,6 @@ private void WriteStructMethod(StructMapping mapping, string n, string ns, objec
564564
for (int i = 0; i < members.Length; i++)
565565
{
566566
MemberMapping m = members[i];
567-
string memberName = m.Name;
568-
object memberValue = GetMemberValue(o, memberName);
569567

570568
bool isSpecified = true;
571569
bool shouldPersist = true;
@@ -586,6 +584,7 @@ private void WriteStructMethod(StructMapping mapping, string n, string ns, objec
586584
{
587585
if (isSpecified && shouldPersist)
588586
{
587+
object memberValue = GetMemberValue(o, m.Name);
589588
WriteMember(memberValue, m.Attribute, m.TypeDesc, o);
590589
}
591590
}
@@ -594,8 +593,9 @@ private void WriteStructMethod(StructMapping mapping, string n, string ns, objec
594593
for (int i = 0; i < members.Length; i++)
595594
{
596595
MemberMapping m = members[i];
597-
string memberName = m.Name;
598-
object memberValue = GetMemberValue(o, memberName);
596+
597+
if (m.Xmlns != null)
598+
continue;
599599

600600
bool isSpecified = true;
601601
bool shouldPersist = true;
@@ -612,27 +612,26 @@ private void WriteStructMethod(StructMapping mapping, string n, string ns, objec
612612
shouldPersist = (bool)method.Invoke(o, Array.Empty<object>());
613613
}
614614

615-
if (m.Xmlns != null)
616-
continue;
617-
618615
bool checkShouldPersist = m.CheckShouldPersist && (m.Elements.Length > 0 || m.Text != null);
619616

620617
if (!checkShouldPersist)
621618
{
622619
shouldPersist = true;
623620
}
624621

625-
object choiceSource = null;
626-
if (m.ChoiceIdentifier != null)
627-
{
628-
choiceSource = GetMemberValue(o, m.ChoiceIdentifier.MemberName);
629-
}
630-
631622
if (isSpecified && shouldPersist)
632623
{
624+
object choiceSource = null;
625+
if (m.ChoiceIdentifier != null)
626+
{
627+
choiceSource = GetMemberValue(o, m.ChoiceIdentifier.MemberName);
628+
}
629+
630+
object memberValue = GetMemberValue(o, m.Name);
633631
WriteMember(memberValue, choiceSource, m.ElementsSortedByDerivation, m.Text, m.ChoiceIdentifier, m.TypeDesc, true);
634632
}
635633
}
634+
636635
if (!mapping.IsSoap)
637636
{
638637
WriteEndElement(o);

0 commit comments

Comments
 (0)