Skip to content

Commit

Permalink
Merge pull request #9 from rafek1241/feature/#8-fix-base-type-attribu…
Browse files Browse the repository at this point in the history
…tes-order

Fix base type attributes order in root container.
  • Loading branch information
rafek1241 authored Mar 16, 2021
2 parents 1116e11 + c6b3d8e commit 0cf2839
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/ReBus.Serializer.XML/XmlSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,16 @@ Type messageType
)
{
var namespaceOfMessage = DefineNamespaceOfMessage(message, messageType);
xmlWriter.WriteStartElement(_options.RootName, namespaceOfMessage);
xmlWriter.WriteStartElement(_options.RootName);

xmlWriter.WriteAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
xmlWriter.WriteAttributeString("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
xmlWriter.WriteAttributeString("xmlns", namespaceOfMessage);

if (_options.IncludeBaseTypeNamespaces)
{
IncludeBaseTypesInElement(xmlWriter, messageType);
}

xmlWriter.WriteAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
xmlWriter.WriteAttributeString("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
}

private void IncludeBaseTypesInElement(XmlTextWriter xmlWriter, Type messageType)
Expand Down
2 changes: 1 addition & 1 deletion tests/ReBus.Serializer.XML.UnitTests/XmlSerializerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public async Task when_passed_message_with_base_types__maps_to_xml_object_with_b

resultAsString.Should()
.Contain(
"xmlns:baseType=\"ReBus.Serializer.XML.UnitTests.Messages.BaseTypes.IAmImplementedInterface\" xmlns:baseType1=\"ReBus.Serializer.XML.UnitTests.Messages.BaseTypes.SubClass\" xmlns:baseType2=\"ReBus.Serializer.XML.UnitTests.Messages.BaseTypes.RootClass\""
"xmlns=\"http://tempuri.org/ReBus.Serializer.XML.UnitTests.Messages.BaseTypes\" xmlns:baseType=\"ReBus.Serializer.XML.UnitTests.Messages.BaseTypes.IAmImplementedInterface\" xmlns:baseType1=\"ReBus.Serializer.XML.UnitTests.Messages.BaseTypes.SubClass\" xmlns:baseType2=\"ReBus.Serializer.XML.UnitTests.Messages.BaseTypes.RootClass\""
);
}

Expand Down

0 comments on commit 0cf2839

Please sign in to comment.