Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
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 @@ -799,30 +799,52 @@ private void WritePrimitive(TypeMapping mapping, string source)
}
else if (mapping.TypeDesc.FormatterName == "String")
{
System.Diagnostics.Debug.Assert(source == "Reader.Value" || source == "Reader.ReadElementString()");
MethodInfo XmlSerializationReader_get_Reader = typeof(XmlSerializationReader).GetMethod(
"get_Reader",
CodeGenerator.InstanceBindingFlags,
Array.Empty<Type>()
);
MethodInfo XmlReader_method = typeof(XmlReader).GetMethod(
source == "Reader.Value" ? "get_Value" : "ReadElementContentAsString",
CodeGenerator.InstanceBindingFlags,
Array.Empty<Type>()
);
if (mapping.TypeDesc.CollapseWhitespace)
ilg.Ldarg(0);
ilg.Ldarg(0);
ilg.Call(XmlSerializationReader_get_Reader);
ilg.Call(XmlReader_method);
if (mapping.TypeDesc.CollapseWhitespace)
System.Diagnostics.Debug.Assert(source == "Reader.Value" || source == "Reader.ReadElementString()" || source == "vals[i]");
if (source == "vals[i]")
{
if (mapping.TypeDesc.CollapseWhitespace)
ilg.Ldarg(0);
LocalBuilder locVals = ilg.GetLocal("vals");
LocalBuilder locI = ilg.GetLocal("i");
ilg.LoadArrayElement(locVals, locI);
if (mapping.TypeDesc.CollapseWhitespace)
{
MethodInfo XmlSerializationReader_CollapseWhitespace = typeof(XmlSerializationReader).GetMethod(
"CollapseWhitespace",
CodeGenerator.InstanceBindingFlags,
null,
new Type[] { typeof(String) },
null
);
ilg.Call(XmlSerializationReader_CollapseWhitespace);
}
}
else
{
MethodInfo XmlSerializationReader_CollapseWhitespace = typeof(XmlSerializationReader).GetMethod(
"CollapseWhitespace",
MethodInfo XmlSerializationReader_get_Reader = typeof(XmlSerializationReader).GetMethod(
"get_Reader",
CodeGenerator.InstanceBindingFlags,
Array.Empty<Type>()
);
MethodInfo XmlReader_method = typeof(XmlReader).GetMethod(
source == "Reader.Value" ? "get_Value" : "ReadElementContentAsString",
CodeGenerator.InstanceBindingFlags,
new Type[] { typeof(string) }
Array.Empty<Type>()
);
ilg.Call(XmlSerializationReader_CollapseWhitespace);
if (mapping.TypeDesc.CollapseWhitespace)
ilg.Ldarg(0);
ilg.Ldarg(0);
ilg.Call(XmlSerializationReader_get_Reader);
ilg.Call(XmlReader_method);
if (mapping.TypeDesc.CollapseWhitespace)
{
MethodInfo XmlSerializationReader_CollapseWhitespace = typeof(XmlSerializationReader).GetMethod(
"CollapseWhitespace",
CodeGenerator.InstanceBindingFlags,
new Type[] { typeof(string) }
);
ilg.Call(XmlSerializationReader_CollapseWhitespace);
}
}
}
else
Expand Down
16 changes: 16 additions & 0 deletions src/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1691,6 +1691,22 @@ public static void SerializeWithDefaultValueSetToNegativeInfinityTest()
Assert.True(result);
}

[Fact]
public static void DeserializeIDREFSIntoStringTest()
{
string xmlstring = @"<?xml version = ""1.0"" encoding = ""utf-8"" ?><Document xmlns = ""http://example.com"" id = ""ID1"" refs=""ID1 ID2 ID3"" ></Document>";
Stream ms = GenerateStreamFromString(xmlstring);
XmlSerializer ser = new XmlSerializer(typeof(MsgDocumentType));
var value = (MsgDocumentType)ser.Deserialize(ms);
Assert.NotNull(value);
Assert.Equal("ID1", value.Id);
Assert.NotNull(value.Refs);
Assert.Equal(3, value.Refs.Count());
Assert.Equal("ID1", value.Refs[0]);
Assert.Equal("ID2", value.Refs[1]);
Assert.Equal("ID3", value.Refs[2]);
}

private static bool SerializeWithDefaultValue<T>(T value, string baseline)
{
XmlSerializer serializer = new XmlSerializer(typeof(T));
Expand Down
12 changes: 12 additions & 0 deletions src/System.Runtime.Serialization.Xml/tests/SerializationTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1243,3 +1243,15 @@ public int IntValue
}
}
}

[Serializable()]
[System.Xml.Serialization.XmlType("MsgDocumentType", Namespace = "http://example.com")]
[System.Xml.Serialization.XmlRoot("Document", Namespace = "http://example.com")]
public partial class MsgDocumentType
{
[System.Xml.Serialization.XmlAttribute("id", DataType = "ID")]
public string Id { get; set; }

[System.Xml.Serialization.XmlAttribute("refs", DataType = "IDREFS")]
public string[] Refs { get; set; }
}