提交 6c91fec4 编写于 作者: S Shin Mao 提交者: GitHub

Fix XmlSchemaTest in ReflectionOnly mode. (dotnet/corefx#14596)

* Fix XmlSchemaTest in ReflectionOnly mode.

Fix dotnet/corefx#11918

* Adress feedback.


Commit migrated from https://github.com/dotnet/corefx/commit/5b4c955cf446cc735a45353d46261d5a6823a2fe
上级 6018b476
......@@ -387,7 +387,7 @@ private void WriteElement(object o, ElementAccessor element, string arrayName, b
throw new PlatformNotSupportedException();
}
WriteStructMethod(mapping, name, ns, o, mapping.TypeDesc.IsNullable, needType: false, parentMapping: parentMapping);
WriteStructMethod(mapping, name, ns, o, element.IsNullable, needType: false, parentMapping: parentMapping);
}
else if (element.Mapping is SpecialMapping)
{
......@@ -477,7 +477,7 @@ private void WriteStructMethod(StructMapping mapping, string n, string ns, objec
{
if (mapping.TypeDesc.Type != null && typeof(XmlSchemaObject).IsAssignableFrom(mapping.TypeDesc.Type))
{
throw new PlatformNotSupportedException(typeof(XmlSchemaObject).ToString());
EscapeName = false;
}
XmlSerializerNamespaces xmlnsSource = null;
......@@ -711,83 +711,82 @@ private void WriteMember(object memberValue, AttributeAccessor attribute, TypeDe
}
}
var a = memberValue as IEnumerable;
// #10593: Add More Tests for Serialization Code
Debug.Assert(a != null);
var e = a.GetEnumerator();
bool shouldAppendWhitespace = false;
if (e != null)
if (memberValue != null)
{
while (e.MoveNext())
var a = (IEnumerable) memberValue;
IEnumerator e = a.GetEnumerator();
bool shouldAppendWhitespace = false;
if (e != null)
{
object ai = e.Current;
if (attribute.IsList)
while (e.MoveNext())
{
string stringValue;
if (attribute.Mapping is EnumMapping)
{
stringValue = WriteEnumMethod((EnumMapping)attribute.Mapping, ai);
}
else
object ai = e.Current;
if (attribute.IsList)
{
if (!WritePrimitiveValue(arrayElementTypeDesc, ai, true, out stringValue))
string stringValue;
if (attribute.Mapping is EnumMapping)
{
// #10593: Add More Tests for Serialization Code
Debug.Assert(ai is byte[]);
stringValue = WriteEnumMethod((EnumMapping)attribute.Mapping, ai);
}
}
// check to see if we can write values of the attribute sequentially
if (canOptimizeWriteListSequence)
{
if (shouldAppendWhitespace)
else
{
Writer.WriteString(" ");
if (!WritePrimitiveValue(arrayElementTypeDesc, ai, true, out stringValue))
{
// #10593: Add More Tests for Serialization Code
Debug.Assert(ai is byte[]);
}
}
if (ai is byte[])
// check to see if we can write values of the attribute sequentially
if (canOptimizeWriteListSequence)
{
WriteValue((byte[])ai);
if (shouldAppendWhitespace)
{
Writer.WriteString(" ");
}
if (ai is byte[])
{
WriteValue((byte[])ai);
}
else
{
WriteValue(stringValue);
}
}
else
{
WriteValue(stringValue);
if (shouldAppendWhitespace)
{
sb.Append(" ");
}
sb.Append(stringValue);
}
}
else
{
if (shouldAppendWhitespace)
{
sb.Append(" ");
}
sb.Append(stringValue);
WriteAttribute(ai, attribute, parent);
}
}
else
{
WriteAttribute(ai, attribute, parent);
}
shouldAppendWhitespace = true;
}
if (attribute.IsList)
{
// check to see if we can write values of the attribute sequentially
if (canOptimizeWriteListSequence)
{
Writer.WriteEndAttribute();
shouldAppendWhitespace = true;
}
else
if (attribute.IsList)
{
if (sb.Length != 0)
// check to see if we can write values of the attribute sequentially
if (canOptimizeWriteListSequence)
{
Writer.WriteEndAttribute();
}
else
{
string ns = attribute.Form == XmlSchemaForm.Qualified ? attribute.Namespace : String.Empty;
WriteAttribute(attribute.Name, ns, sb.ToString());
if (sb.Length != 0)
{
string ns = attribute.Form == XmlSchemaForm.Qualified ? attribute.Namespace : String.Empty;
WriteAttribute(attribute.Name, ns, sb.ToString());
}
}
}
}
......
......@@ -2331,9 +2331,6 @@ public static void XML_TypeWithFieldsOrdered()
Assert.Equal(value.StringField2, actual.StringField2);
}
#if ReflectionOnly
[ActiveIssue(14260)]
#endif
[Fact]
public static void XmlSchemaTest()
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册