diff options
author | Huangli Wu <huanwu@microsoft.com> | 2018-01-12 20:53:57 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-12 20:53:57 +0300 |
commit | a8d34fe82b2cbecef4d76a042ee3d03ce911fd59 (patch) | |
tree | db3d01bdb51a4191792d3f940bb151a40750031a /src | |
parent | 3cfcacde6aa7338fa1714ae90e6be8cf802ca6c0 (diff) |
Re-apply Changes in #25562 on if/else fix. (#26285)
Diffstat (limited to 'src')
-rw-r--r-- | src/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationReader.cs | 58 | ||||
-rw-r--r-- | src/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationWriter.cs | 10 |
2 files changed, 46 insertions, 22 deletions
diff --git a/src/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationReader.cs b/src/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationReader.cs index e891a9c18d..c9882b4b25 100644 --- a/src/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationReader.cs +++ b/src/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationReader.cs @@ -3190,7 +3190,7 @@ namespace System.Xml.Serialization { for (StructMapping derived = mapping.DerivedMappings; derived != null; derived = derived.NextDerivedMapping) { - Writer.Write("else if ("); + Writer.Write("if ("); WriteQNameEqual("xsiType", derived.TypeName, derived.Namespace); Writer.WriteLine(")"); Writer.Indent++; @@ -3227,7 +3227,7 @@ namespace System.Xml.Serialization if (m is EnumMapping) { EnumMapping mapping = (EnumMapping)m; - Writer.Write("else if ("); + Writer.Write("if ("); WriteQNameEqual("xsiType", mapping.TypeName, mapping.Namespace); Writer.WriteLine(") {"); Writer.Indent++; @@ -3250,7 +3250,7 @@ namespace System.Xml.Serialization ArrayMapping mapping = (ArrayMapping)m; if (mapping.TypeDesc.HasDefaultConstructor) { - Writer.Write("else if ("); + Writer.Write("if ("); WriteQNameEqual("xsiType", mapping.TypeName, mapping.Namespace); Writer.WriteLine(") {"); Writer.Indent++; @@ -3397,10 +3397,10 @@ namespace System.Xml.Serialization Writer.Indent--; } Writer.WriteLine("}"); + Writer.WriteLine("else {"); + Writer.Indent++; WriteDerivedTypes(structMapping, !useReflection && !structMapping.TypeDesc.IsRoot, typeName); if (structMapping.TypeDesc.IsRoot) WriteEnumAndArrayTypes(); - Writer.WriteLine("else"); - Writer.Indent++; if (structMapping.TypeDesc.IsRoot) Writer.Write("return ReadTypedPrimitive(("); else @@ -3409,7 +3409,9 @@ namespace System.Xml.Serialization Writer.WriteLine(")xsiType);"); Writer.Indent--; Writer.WriteLine("}"); - + if (structMapping.TypeDesc.IsRoot) + Writer.Indent--; + Writer.WriteLine("}"); if (structMapping.TypeDesc.IsNullable) Writer.WriteLine("if (isNull) return null;"); @@ -4350,16 +4352,27 @@ namespace System.Xml.Serialization ElementAccessor e = elements[j]; string ns = e.Form == XmlSchemaForm.Qualified ? e.Namespace : ""; if (!isSequence && e.Any && (e.Name == null || e.Name.Length == 0)) continue; - if (!firstElement || (!isSequence && count > 0)) + if (!isSequence) { - Writer.Write("else "); + if (firstElement && count == 0) + { + Writer.WriteLine("do {"); + Writer.Indent++; + } } - else if (isSequence) + else { - Writer.Write("case "); - Writer.Write(cases.ToString(CultureInfo.InvariantCulture)); - Writer.WriteLine(":"); - Writer.Indent++; + if (!firstElement || (!isSequence && count > 0)) + { + Writer.Write("else "); + } + else if (isSequence) + { + Writer.Write("case "); + Writer.Write(cases.ToString(CultureInfo.InvariantCulture)); + Writer.WriteLine(":"); + Writer.Indent++; + } } count++; firstElement = false; @@ -4449,6 +4462,10 @@ namespace System.Xml.Serialization Writer.Write(member.ParamsReadSource); Writer.WriteLine(" = true;"); } + if (!isSequence) + { + Writer.WriteLine("break;"); + } Writer.Indent--; Writer.WriteLine("}"); } @@ -4475,10 +4492,10 @@ namespace System.Xml.Serialization if (count > 0) { if (isSequence) + { Writer.WriteLine("default:"); - else - Writer.WriteLine("else {"); - Writer.Indent++; + Writer.Indent++; + } } WriteMemberElementsElse(anyElement, elementElseString); if (count > 0) @@ -4488,7 +4505,14 @@ namespace System.Xml.Serialization Writer.WriteLine("break;"); } Writer.Indent--; - Writer.WriteLine("}"); + if (!isSequence) + { + Writer.WriteLine("} while (false);"); + } + else + { + Writer.WriteLine("}"); + } } } diff --git a/src/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationWriter.cs b/src/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationWriter.cs index c28af8e265..766ee3628a 100644 --- a/src/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationWriter.cs +++ b/src/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationWriter.cs @@ -2919,7 +2919,7 @@ namespace System.Xml.Serialization for (StructMapping derived = mapping.DerivedMappings; derived != null; derived = derived.NextDerivedMapping) { string fullTypeName = derived.TypeDesc.CSharpName; - Writer.Write("else if ("); + Writer.Write("if ("); WriteTypeCompare("t", fullTypeName, derived.TypeDesc.UseReflection); Writer.WriteLine(") {"); Writer.Indent++; @@ -2957,7 +2957,7 @@ namespace System.Xml.Serialization { EnumMapping mapping = (EnumMapping)m; string fullTypeName = mapping.TypeDesc.CSharpName; - Writer.Write("else if ("); + Writer.Write("if ("); WriteTypeCompare("t", fullTypeName, mapping.TypeDesc.UseReflection); Writer.WriteLine(") {"); Writer.Indent++; @@ -2989,7 +2989,7 @@ namespace System.Xml.Serialization ArrayMapping mapping = m as ArrayMapping; if (mapping == null || m.IsSoap) continue; string fullTypeName = mapping.TypeDesc.CSharpName; - Writer.Write("else if ("); + Writer.Write("if ("); if (mapping.TypeDesc.IsArray) WriteArrayTypeCompare("t", fullTypeName, mapping.TypeDesc.ArrayElementTypeDesc.CSharpName, mapping.TypeDesc.UseReflection); else @@ -3059,12 +3059,12 @@ namespace System.Xml.Serialization WriteTypeCompare("t", fullTypeName, mapping.TypeDesc.UseReflection); Writer.WriteLine(") {"); Writer.WriteLine("}"); + Writer.WriteLine("else {"); + Writer.Indent++; WriteDerivedTypes(mapping); if (mapping.TypeDesc.IsRoot) WriteEnumAndArrayTypes(); - Writer.WriteLine("else {"); - Writer.Indent++; if (mapping.TypeDesc.IsRoot) { Writer.WriteLine("WriteTypedPrimitive(n, ns, o, true);"); |