Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1981,9 +1981,12 @@ private void WriteAttribute(Member member, object? attr = null)
}
else if (special.TypeDesc.CanBeAttributeValue)
{
// https://github.com/dotnet/runtime/issues/1398:
// To Support special.TypeDesc.CanBeAttributeValue == true
throw new NotImplementedException("special.TypeDesc.CanBeAttributeValue");
if (attr is not XmlAttribute xmlAttribute)
{
return;
}

value = xmlAttribute;
}
else
throw new InvalidOperationException(SR.XmlInternalError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,6 @@

public static partial class XmlSerializerTests
{
// Move this test to XmlSerializerTests.cs once #1398 is fixed for the ReflectionOnly serializer.
[Fact]
public static void Xml_CustomDocumentWithXmlAttributesAsNodes()
{
var customDoc = new CustomDocument();
var customElement = new CustomElement() { Name = "testElement" };
customElement.AddAttribute(customDoc.CreateAttribute("regularAttribute", "regularValue"));
customElement.AddAttribute(customDoc.CreateCustomAttribute("customAttribute", "customValue"));
customDoc.CustomItems.Add(customElement);
var element = customDoc.Document.CreateElement("regularElement");
var innerElement = customDoc.Document.CreateElement("innerElement");
innerElement.InnerXml = "<leafElement>innerText</leafElement>";
element.InnerText = "regularText";
element.AppendChild(innerElement);
element.Attributes.Append(customDoc.CreateAttribute("regularElementAttribute", "regularElementAttributeValue"));
customDoc.AddItem(element);
var actual = SerializeAndDeserialize(customDoc,
WithXmlHeader(@"<customElement name=""testElement"" regularAttribute=""regularValue"" customAttribute=""customValue""/>"), skipStringCompare: true);
Assert.NotNull(actual);
}

// Move this test to XmlSerializerTests.cs once #1401 is fixed for the ReflectionOnly serializer.
[Fact]
public static void Xml_DerivedIXmlSerializable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,26 @@ public static void Xml_XmlAnyAttributeTest()
}
}

[Fact]
public static void Xml_CustomDocumentWithXmlAttributesAsNodes()
{
var customDoc = new CustomDocument();
var customElement = new CustomElement() { Name = "testElement" };
customElement.AddAttribute(customDoc.CreateAttribute("regularAttribute", "regularValue"));
customElement.AddAttribute(customDoc.CreateCustomAttribute("customAttribute", "customValue"));
customDoc.CustomItems.Add(customElement);
var element = customDoc.Document.CreateElement("regularElement");
var innerElement = customDoc.Document.CreateElement("innerElement");
innerElement.InnerXml = "<leafElement>innerText</leafElement>";
element.InnerText = "regularText";
element.AppendChild(innerElement);
element.Attributes.Append(customDoc.CreateAttribute("regularElementAttribute", "regularElementAttributeValue"));
customDoc.AddItem(element);
var actual = SerializeAndDeserialize(customDoc,
WithXmlHeader(@"<customElement name=""testElement"" regularAttribute=""regularValue"" customAttribute=""customValue""/>"), skipStringCompare: true);
Assert.NotNull(actual);
}
Comment on lines +643 to +646

[Fact]
public static void Xml_Struct()
{
Expand Down
Loading