Imported Upstream version 4.2.2.29

Former-commit-id: f069081cc0821095435a845c961ae61cbbc95121
This commit is contained in:
Xamarin Public Jenkins
2016-01-18 21:29:19 -05:00
parent 8cb7d04924
commit 3c6daee652
1830 changed files with 496 additions and 305641 deletions

View File

@@ -181,8 +181,8 @@ namespace System.Runtime.Serialization
void ReadISerializable (ClassDataContract classContract)
{
ConstructorInfo ctor = classContract.GetISerializableConstructor ();
context.ReadSerializationInfo (xmlReader, classContract.UnderlyingType);
ctor.Invoke (objectLocal, new object [] {context.GetStreamingContext ()});
var info = context.ReadSerializationInfo (xmlReader, classContract.UnderlyingType);
ctor.Invoke (objectLocal, new object [] {info, context.GetStreamingContext ()});
}
void ReadClass (ClassDataContract classContract)

View File

@@ -469,8 +469,13 @@ namespace System.Runtime.Serialization
PrimitiveDataContract primitiveContract = PrimitiveDataContract.GetPrimitiveDataContract(memberType);
if (primitiveContract != null && !writeXsiType)
primitiveContract.XmlFormatContentWriterMethod.Invoke (writer, new object [] {memberValue});
else
InternalSerialize(XmlFormatGeneratorStatics.InternalSerializeMethod, () => memberValue, memberType, writeXsiType);
else {
// InternalSerialize(XmlFormatGeneratorStatics.InternalSerializeMethod, () => memberValue, memberType, writeXsiType);
var typeHandleValue = Type.GetTypeHandle (memberValue);
var isDeclaredType = typeHandleValue.Equals (CodeInterpreter.ConvertValue (memberValue, memberType, Globals.TypeOfObject));
ctx.InternalSerialize (writer, memberValue, isDeclaredType, writeXsiType, DataContract.GetId (memberType.TypeHandle), memberType.TypeHandle);
}
}
else
{
@@ -500,22 +505,19 @@ namespace System.Runtime.Serialization
if (isNull2) {
XmlFormatGeneratorStatics.WriteNullMethod.Invoke (ctx, new object [] {writer, memberType, DataContract.IsTypeSerializable(memberType)});
} else {
InternalSerialize((isNullableOfT ? XmlFormatGeneratorStatics.InternalSerializeMethod : XmlFormatGeneratorStatics.InternalSerializeReferenceMethod),
() => memberValue, memberType, writeXsiType);
var typeHandleValue = Type.GetTypeHandle (memberValue);
var isDeclaredType = typeHandleValue.Equals (CodeInterpreter.ConvertValue (memberValue, memberType, Globals.TypeOfObject));
if (isNullableOfT)
ctx.InternalSerialize (writer, memberValue, isDeclaredType, writeXsiType, DataContract.GetId (memberType.TypeHandle), memberType.TypeHandle);
else
ctx.InternalSerializeReference (writer, memberValue, isDeclaredType, writeXsiType, DataContract.GetId (memberType.TypeHandle), memberType.TypeHandle);
//InternalSerialize((isNullableOfT ? XmlFormatGeneratorStatics.InternalSerializeMethod : XmlFormatGeneratorStatics.InternalSerializeReferenceMethod), () => memberValue, memberType, writeXsiType);
}
}
}
}
}
void InternalSerialize (MethodInfo methodInfo, Func<object> memberValue, Type memberType, bool writeXsiType)
{
var v = memberValue ();
var typeHandleValue = Type.GetTypeHandle (v);
var isDeclaredType = typeHandleValue.Equals (CodeInterpreter.ConvertValue (v, memberType, Globals.TypeOfObject));
methodInfo.Invoke (ctx, new object [] {writer, memberValue != null ? v : null, isDeclaredType, writeXsiType, DataContract.GetId (memberType.TypeHandle), memberType.TypeHandle});
}
object UnwrapNullableObject(Func<object> memberValue, ref Type memberType, out bool isNull)// Leaves !HasValue on stack
{
object v = memberValue ();

View File

@@ -5,10 +5,12 @@ System.Runtime.Serialization/Bug2843Test.cs
System.Runtime.Serialization/Bug3258Test.cs
System.Runtime.Serialization/Bug242Test.cs
System.Runtime.Serialization/Bug695203Test.cs
System.Runtime.Serialization/Bug36100.cs
System.Runtime.Serialization/DataContractResolverTest.cs
System.Runtime.Serialization/DataContractSerializerTest_DuplicateQName.cs
System.Runtime.Serialization/DataContractSerializerTest_NullableWithDictionary.cs
System.Runtime.Serialization/DataContractSerializerTest_InvalidCharacters.cs
System.Runtime.Serialization/DataContractSerializerTest_ISerializable.cs
System.Runtime.Serialization/DataContractSerializerTest.cs
System.Runtime.Serialization/KnownTypeAttributeTest.cs
System.Runtime.Serialization/XmlObjectSerializerTest.cs

View File

@@ -0,0 +1 @@
0eb5fd5cac80a730d30a79b0d0fbf4155fb5ddf1

View File

@@ -0,0 +1,114 @@
//
// DataContractSerializerTest_ISerializable.cs
//
// Author:
// Aaron Bockover <abock@xamarin.com>
//
// Copyright 2015 Xamarin Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Xml;
using NUnit.Framework;
namespace MonoTests.System.Runtime.Serialization
{
[TestFixture]
public class DataContractSerializerTest_ISerializable
{
[Serializable]
sealed class TestClassISerializable : ISerializable
{
public string Foo { get; }
public TestClassISerializable (string foo)
{
Foo = foo;
}
TestClassISerializable (SerializationInfo info, StreamingContext context)
{
Foo = info.GetString ("foo");
}
void ISerializable.GetObjectData (SerializationInfo info, StreamingContext context)
{
info.AddValue ("foo", Foo);
}
}
// Tests that the ISerializable constructor is properly invoked, which
// regressed when integrating MS Reference Source DCS, et. al.:
// https://bugzilla.xamarin.com/show_bug.cgi?id=37171
[Test]
public void TestISerializableCtor ()
{
var serializer = new DataContractSerializer (
typeof(TestClassISerializable),
new DataContractSerializerSettings {
DataContractResolver = new Resolver ()
}
);
var stream = new MemoryStream ();
var expected = new TestClassISerializable ("hello world");
serializer.WriteObject (stream, expected);
stream.Flush ();
stream.Position = 0;
var actual = (TestClassISerializable)serializer.ReadObject (stream);
Assert.AreEqual (expected.Foo, actual.Foo, "#DCS_ISer_Ctor");
}
// Resolver to force DCS to serialize any type, ensuring the ISerializable
// path will be taken for objects implementing that interface
class Resolver : DataContractResolver
{
public override Type ResolveName (string typeName, string typeNamespace,
Type declaredType, DataContractResolver knownTypeResolver)
{
return Type.GetType (typeNamespace == null
? typeName
: typeNamespace + "." + typeName
);
}
public override bool TryResolveType (Type type, Type declaredType,
DataContractResolver knownTypeResolver,
out XmlDictionaryString typeName,
out XmlDictionaryString typeNamespace)
{
var name = type.FullName;
var namesp = type.Namespace;
name = name.Substring (type.Namespace.Length + 1);
typeName = new XmlDictionaryString (XmlDictionary.Empty, name, 0);
typeNamespace = new XmlDictionaryString (XmlDictionary.Empty, namesp, 0);
return true;
}
}
}
}