Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
fix one more xml serializer test
Browse files Browse the repository at this point in the history
  • Loading branch information
krwq committed Jul 15, 2016
1 parent 1d12b57 commit 9a4b239
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 90 deletions.
25 changes: 1 addition & 24 deletions src/System.Xml/src/System.Xml.csproj
Expand Up @@ -495,15 +495,7 @@
</ItemGroup>
<!-- Embedded DTD files -->
<ItemGroup>
<!--<EmbeddedResource Include="Resources\Res.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Res.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="Resources\XmlUtilsRes.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>XmlUtilsRes.Designer.cs</LastGenOutput>
<CustomToolNamespace>System.Xml.Utils</CustomToolNamespace>
</EmbeddedResource>-->
<!-- TODO: check why was this embedded on desktop - no test failures observed after commenting this out -->
<!--<EmbeddedResource Include="Utils\DTDs\XHTML10\no_comments\xhtml1-strict.dtd">
<LogicalName>xhtml1-strict.dtd</LogicalName>
</EmbeddedResource>
Expand All @@ -525,11 +517,6 @@
<EmbeddedResource Include="Utils\DTDs\RSS091\no_comments\rss-0.91.dtd">
<LogicalName>rss-0.91.dtd</LogicalName>
</EmbeddedResource>-->
<!--<EmbeddedResource Include="Workarounds\CodeDom\Compiler\Res_CodeDom.resX">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Res_CodeDom.Designer.cs</LastGenOutput>
<CustomToolNamespace>System.CodeDom.Compiler</CustomToolNamespace>
</EmbeddedResource>-->
</ItemGroup>
<ItemGroup Condition="'$(TargetGroup)' != 'net46'">
<EmbeddedResource Include="Resources\$(AssemblyName).rd.xml" />
Expand All @@ -538,11 +525,6 @@
<None Include="project.json" />
</ItemGroup>
<ItemGroup>
<!--<Compile Include="Resources\XmlUtilsRes.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>XmlUtilsRes.resx</DependentUpon>
</Compile>-->
<Compile Include="System\Xml\Xsl\IlGen\GenerateHelper.cs" />
<Compile Include="System\Xml\Xsl\IlGen\IteratorDescriptor.cs" />
<Compile Include="System\Xml\Xsl\IlGen\OptimizerPatterns.cs" />
Expand Down Expand Up @@ -818,11 +800,6 @@
<Compile Include="Workarounds\CodeDom\Compiler\GeneratorSupport.cs" />
<Compile Include="Workarounds\CodeDom\Compiler\ICodeCompiler.cs" />
<Compile Include="Workarounds\CodeDom\Compiler\ICodeGenerator.cs" />
<!--<Compile Include="Workarounds\CodeDom\Compiler\Res_CodeDom.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Res_CodeDom.resX</DependentUpon>
</Compile>-->
<Compile Include="Workarounds\CodeDom\Compiler\TempFiles.cs" />
<Compile Include="Workarounds\CodeDom\MemberAttributes.cs" />
<Compile Include="Workarounds\CodeDom\RedistVersionInfo.cs" />
Expand Down
2 changes: 2 additions & 0 deletions src/System.Xml/src/System/Xml/Serialization/Compilation.cs
Expand Up @@ -53,6 +53,7 @@ private TempAssembly()

internal TempAssembly(XmlMapping[] xmlMappings, Type[] types, string defaultNamespace, string location, Evidence evidence)
{
#if !NET_NATIVE
bool containsSoapMapping = false;
for (int i = 0; i < xmlMappings.Length; i++)
{
Expand Down Expand Up @@ -89,6 +90,7 @@ internal TempAssembly(XmlMapping[] xmlMappings, Type[] types, string defaultName
{
_assembly = GenerateAssembly(xmlMappings, types, defaultNamespace, evidence, XmlSerializerCompilerParameters.Create(location), null, _assemblies);
}
#endif

#if DEBUG
// use exception in the place of Debug.Assert to avoid throwing asserts from a server process such as aspnet_ewp.exe
Expand Down
Expand Up @@ -425,7 +425,7 @@ private string GetChoiceIdentifierSource(MemberMapping[] mappings, MemberMapping
}
#if DEBUG
// use exception in the place of Debug.Assert to avoid throwing asserts from a server process such as aspnet_ewp.exe
if (choiceSource == null) throw new InvalidOperationException(string.Format(SR.XmlInternalErrorDetails, "Can not find " + member.ChoiceIdentifier.MemberName + " in the members mapping."));
if (choiceSource == null) throw new InvalidOperationException(SR.Format(SR.XmlInternalErrorDetails, "Can not find " + member.ChoiceIdentifier.MemberName + " in the members mapping."));
#endif

}
Expand Down Expand Up @@ -746,7 +746,7 @@ private void WritePrimitive(TypeMapping mapping, string source)
if (mapping is EnumMapping)
{
string enumMethodName = ReferenceMapping(mapping);
if (enumMethodName == null) throw new InvalidOperationException(string.Format(SR.XmlMissingMethodEnum, mapping.TypeDesc.Name));
if (enumMethodName == null) throw new InvalidOperationException(SR.Format(SR.XmlMissingMethodEnum, mapping.TypeDesc.Name));
// For enum, its read method (eg. Read1_Gender) could be called multiple times
// prior to its declaration.
MethodBuilder methodBuilder = EnsureMethodBuilder(typeBuilder,
Expand Down Expand Up @@ -851,49 +851,30 @@ private void WritePrimitive(TypeMapping mapping, string source)
}
else if (mapping.TypeDesc.FormatterName == "String")
{
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",
new Type[] { typeof(String) }
);
ilg.Call(XmlSerializationReader_CollapseWhitespace);
}
}
else
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()");
MethodInfo XmlSerializationReader_get_Reader = typeof(XmlSerializationReader).GetMethod(
"get_Reader",
MethodInfo XmlSerializationReader_CollapseWhitespace = typeof(XmlSerializationReader).GetMethod(
"CollapseWhitespace",
CodeGenerator.InstanceBindingFlags,
Array.Empty<Type>()
);
MethodInfo XmlReader_method = typeof(XmlReader).GetMethod(
source == "Reader.Value" ? "get_Value" : "ReadElementContentAsString",
CodeGenerator.InstanceBindingFlags,
Array.Empty<Type>()
new Type[] { typeof(String) }
);
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);
}
ilg.Call(XmlSerializationReader_CollapseWhitespace);
}
}
else
Expand Down Expand Up @@ -976,8 +957,8 @@ private void WritePrimitive(TypeMapping mapping, string source)
private string MakeUnique(EnumMapping mapping, string name)
{
string uniqueName = name;
object m = Enums[uniqueName];
if (m != null)
EnumMapping m;
if (Enums.TryGetValue(uniqueName, out m))
{
if (m == mapping)
{
Expand Down Expand Up @@ -1079,7 +1060,8 @@ private void WriteEnumMethod(EnumMapping mapping)
if (mapping.IsFlags)
WriteHashtable(mapping, mapping.TypeDesc.Name, out get_TableName);

string methodName = (string)MethodNames[mapping];
string methodName;
MethodNames.TryGetValue(mapping, out methodName);
string fullTypeName = mapping.TypeDesc.CSharpName;
List<Type> argTypes = new List<Type>();
List<string> argNames = new List<string>();
Expand Down Expand Up @@ -1199,7 +1181,7 @@ private void WriteDerivedTypes(StructMapping mapping, bool isTypedReturn, string
string methodName = ReferenceMapping(derived);
#if DEBUG
// use exception in the place of Debug.Assert to avoid throwing asserts from a server process such as aspnet_ewp.exe
if (methodName == null) throw new InvalidOperationException(string.Format(SR.XmlInternalErrorMethod, derived.TypeDesc.Name));
if (methodName == null) throw new InvalidOperationException(SR.Format(SR.XmlInternalErrorMethod, derived.TypeDesc.Name));
#endif

List<Type> argTypes = new List<Type>();
Expand Down Expand Up @@ -1255,7 +1237,7 @@ private void WriteEnumAndArrayTypes()
string methodName = ReferenceMapping(mapping);
#if DEBUG
// use exception in the place of Debug.Assert to avoid throwing asserts from a server process such as aspnet_ewp.exe
if (methodName == null) throw new InvalidOperationException(string.Format(SR.XmlInternalErrorMethod, mapping.TypeDesc.Name));
if (methodName == null) throw new InvalidOperationException(SR.Format(SR.XmlInternalErrorMethod, mapping.TypeDesc.Name));
#endif
LocalBuilder eLoc = ilg.DeclareOrGetLocal(typeof(object), "e");
MethodBuilder methodBuilder = EnsureMethodBuilder(typeBuilder,
Expand Down Expand Up @@ -1335,7 +1317,8 @@ private void WriteEnumAndArrayTypes()

private void WriteNullableMethod(NullableMapping nullableMapping)
{
string methodName = (string)MethodNames[nullableMapping];
string methodName;
MethodNames.TryGetValue(nullableMapping, out methodName);
ilg = new CodeGenerator(this.typeBuilder);
ilg.BeginMethod(
nullableMapping.TypeDesc.Type,
Expand Down Expand Up @@ -1384,7 +1367,8 @@ private void WriteStructMethod(StructMapping structMapping)

private void WriteLiteralStructMethod(StructMapping structMapping)
{
string methodName = (string)MethodNames[structMapping];
string methodName;
MethodNames.TryGetValue(structMapping, out methodName);
string typeName = structMapping.TypeDesc.CSharpName;
ilg = new CodeGenerator(this.typeBuilder);
List<Type> argTypes = new List<Type>();
Expand Down Expand Up @@ -1625,7 +1609,7 @@ private void WriteLiteralStructMethod(StructMapping structMapping)
{
StructMapping declaringMapping;
structMapping.FindDeclaringMapping(mapping, out declaringMapping, structMapping.TypeName);
throw new InvalidOperationException(string.Format(SR.XmlSequenceHierarchy, structMapping.TypeDesc.FullName, mapping.Name, declaringMapping.TypeDesc.FullName, "Order"));
throw new InvalidOperationException(SR.Format(SR.XmlSequenceHierarchy, structMapping.TypeDesc.FullName, mapping.Name, declaringMapping.TypeDesc.FullName, "Order"));
}
if (mapping.Attribute == null && mapping.Elements.Length == 1 && mapping.Elements[0].Mapping is ArrayMapping)
{
Expand Down Expand Up @@ -3041,7 +3025,7 @@ private void WriteElement(string source, string arrayName, string choiceSource,
string methodName = ReferenceMapping(element.Mapping);
#if DEBUG
// use exception in the place of Debug.Assert to avoid throwing asserts from a server process such as aspnet_ewp.exe
if (methodName == null) throw new InvalidOperationException(string.Format(SR.XmlInternalErrorMethod, element.Mapping.TypeDesc.Name));
if (methodName == null) throw new InvalidOperationException(SR.Format(SR.XmlInternalErrorMethod, element.Mapping.TypeDesc.Name));
#endif
WriteSourceBegin(source);
ilg.Ldarg(0);
Expand Down Expand Up @@ -3082,7 +3066,7 @@ private void WriteElement(string source, string arrayName, string choiceSource,
ilg.Else();
doEndIf = true;
}
if (element.Default != null && element.Default != DBNull.Value && element.Mapping.TypeDesc.IsValueType)
if (element.Default != null && !Globals.IsDBNullValue(element.Default) && element.Mapping.TypeDesc.IsValueType)
{
MethodInfo XmlSerializationReader_get_Reader = typeof(XmlSerializationReader).GetMethod(
"get_Reader",
Expand Down Expand Up @@ -3150,7 +3134,7 @@ private void WriteElement(string source, string arrayName, string choiceSource,
string methodName = ReferenceMapping(mapping);
#if DEBUG
// use exception in the place of Debug.Assert to avoid throwing asserts from a server process such as aspnet_ewp.exe
if (methodName == null) throw new InvalidOperationException(string.Format(SR.XmlInternalErrorMethod, mapping.TypeDesc.Name));
if (methodName == null) throw new InvalidOperationException(SR.Format(SR.XmlInternalErrorMethod, mapping.TypeDesc.Name));
#endif

if (checkForNull)
Expand Down Expand Up @@ -3280,7 +3264,7 @@ private void WriteElement(string source, string arrayName, string choiceSource,
{
#if DEBUG
// use exception in the place of Debug.Assert to avoid throwing asserts from a server process such as aspnet_ewp.exe
if (choiceSource == null) throw new InvalidOperationException(string.Format(SR.XmlInternalErrorDetails, "need parent for the " + source));
if (choiceSource == null) throw new InvalidOperationException(SR.Format(SR.XmlInternalErrorDetails, "need parent for the " + source));
#endif

WriteSourceBegin(choiceSource);
Expand Down

0 comments on commit 9a4b239

Please sign in to comment.