Imported Upstream version 5.8.0.22

Former-commit-id: df344e34b07851d296efb3e6604c8db42b6f7aa3
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-10-19 20:04:20 +00:00
parent 5f4a27cc8a
commit 7d05485754
5020 changed files with 114082 additions and 186061 deletions

View File

@@ -8,7 +8,6 @@
<TypeParameter Name="type" DataContractSerializer="Public"/>
<TypeEnumerableParameter Name="knownTypes" DataContractSerializer="Public"/>
</Method>
<Property Name="Option" Dynamic="Required" />
</Type>
<Type Name="KeyValuePairAdapter`2" Dynamic="Required All" />
<!-- Reflection-based serialization requires the entries below. -->

View File

@@ -465,9 +465,14 @@ namespace System.Runtime.Serialization
_helper.IncrementCollectionCount(xmlWriter, obj, context);
}
internal IEnumerator GetEnumeratorForCollection(object obj, out Type enumeratorReturnType)
internal IEnumerator GetEnumeratorForCollection(object obj)
{
return _helper.GetEnumeratorForCollection(obj, out enumeratorReturnType);
return _helper.GetEnumeratorForCollection(obj);
}
internal Type GetCollectionElementType()
{
return _helper.GetCollectionElementType();
}
private class CollectionDataContractCriticalHelper : DataContract.DataContractCriticalHelper
@@ -785,7 +790,7 @@ namespace System.Runtime.Serialization
{
_incrementCollectionCountDelegate = (x, o, c) =>
{
context.IncrementCollectionCount(x, (ICollection)o);
c.IncrementCollectionCount(x, (ICollection)o);
};
}
break;
@@ -840,7 +845,7 @@ namespace System.Runtime.Serialization
private CreateGenericDictionaryEnumeratorDelegate _createGenericDictionaryEnumeratorDelegate;
internal IEnumerator GetEnumeratorForCollection(object obj, out Type enumeratorReturnType)
internal IEnumerator GetEnumeratorForCollection(object obj)
{
IEnumerator enumerator = ((IEnumerable)obj).GetEnumerator();
if (Kind == CollectionKind.GenericDictionary)
@@ -859,55 +864,57 @@ namespace System.Runtime.Serialization
enumerator = new DictionaryEnumerator(((IDictionary)obj).GetEnumerator());
}
enumeratorReturnType = EnumeratorReturnType;
return enumerator;
}
private Type _enumeratorReturnType;
public Type EnumeratorReturnType
internal Type GetCollectionElementType()
{
get
{
_enumeratorReturnType = _enumeratorReturnType ?? GetCollectionEnumeratorReturnType();
return _enumeratorReturnType;
}
}
private Type GetCollectionEnumeratorReturnType()
{
Type enumeratorReturnType;
Type enumeratorType = null;
if (Kind == CollectionKind.GenericDictionary)
{
var keyValueTypes = ItemType.GetGenericArguments();
enumeratorReturnType = Globals.TypeOfKeyValue.MakeGenericType(keyValueTypes);
Type[] keyValueTypes = ItemType.GetGenericArguments();
enumeratorType = Globals.TypeOfGenericDictionaryEnumerator.MakeGenericType(keyValueTypes);
}
else if (Kind == CollectionKind.Dictionary)
{
enumeratorReturnType = Globals.TypeOfObject;
}
else if (Kind == CollectionKind.GenericCollection
|| Kind == CollectionKind.GenericList)
{
enumeratorReturnType = ItemType;
enumeratorType = Globals.TypeOfDictionaryEnumerator;
}
else
{
var enumeratorType = GetEnumeratorMethod.ReturnType;
if (enumeratorType.IsGenericType)
enumeratorType = GetEnumeratorMethod.ReturnType;
}
MethodInfo getCurrentMethod = enumeratorType.GetMethod(Globals.GetCurrentMethodName, BindingFlags.Instance | BindingFlags.Public, Array.Empty<Type>());
if (getCurrentMethod == null)
{
if (enumeratorType.IsInterface)
{
MethodInfo getCurrentMethod = enumeratorType.GetMethod(Globals.GetCurrentMethodName, BindingFlags.Instance | BindingFlags.Public, Array.Empty<Type>());
enumeratorReturnType = getCurrentMethod.ReturnType;
getCurrentMethod = XmlFormatGeneratorStatics.GetCurrentMethod;
}
else
{
enumeratorReturnType = Globals.TypeOfObject;
Type ienumeratorInterface = Globals.TypeOfIEnumerator;
if (Kind == CollectionKind.GenericDictionary || Kind == CollectionKind.GenericCollection || Kind == CollectionKind.GenericEnumerable)
{
Type[] interfaceTypes = enumeratorType.GetInterfaces();
foreach (Type interfaceType in interfaceTypes)
{
if (interfaceType.IsGenericType
&& interfaceType.GetGenericTypeDefinition() == Globals.TypeOfIEnumeratorGeneric
&& interfaceType.GetGenericArguments()[0] == ItemType)
{
ienumeratorInterface = interfaceType;
break;
}
}
}
getCurrentMethod = GetTargetMethodWithName(Globals.GetCurrentMethodName, enumeratorType, ienumeratorInterface);
}
}
return enumeratorReturnType;
Type elementType = getCurrentMethod.ReturnType;
return elementType;
}
private static MethodInfo s_buildCreateGenericDictionaryEnumerator;

View File

@@ -1 +1 @@
d1903e135a02d45d5e9f0e7ae1c8d8105ccaaed0
257107efef5642950e450c041348b02bbd3e9008

View File

@@ -193,7 +193,52 @@ namespace System.Runtime.Serialization.Json
}
else if (keyParseMode == KeyParseMode.UsingCustomParse)
{
pairKey = keyDataContract.ParseMethod.Invoke(null, new object[] { keyString });
TypeCode typeCode = Type.GetTypeCode(keyDataContract.UnderlyingType);
switch (typeCode)
{
case TypeCode.Boolean:
pairKey = Boolean.Parse(keyString);
break;
case TypeCode.Int16:
pairKey = Int16.Parse(keyString);
break;
case TypeCode.Int32:
pairKey = Int32.Parse(keyString);
break;
case TypeCode.Int64:
pairKey = Int64.Parse(keyString);
break;
case TypeCode.Char:
pairKey = Char.Parse(keyString);
break;
case TypeCode.Byte:
pairKey = Byte.Parse(keyString);
break;
case TypeCode.SByte:
pairKey = SByte.Parse(keyString);
break;
case TypeCode.Double:
pairKey = Double.Parse(keyString);
break;
case TypeCode.Decimal:
pairKey = Decimal.Parse(keyString);
break;
case TypeCode.Single:
pairKey = Single.Parse(keyString);
break;
case TypeCode.UInt16:
pairKey = UInt16.Parse(keyString);
break;
case TypeCode.UInt32:
pairKey = UInt32.Parse(keyString);
break;
case TypeCode.UInt64:
pairKey = UInt64.Parse(keyString);
break;
default:
pairKey = keyDataContract.ParseMethod.Invoke(null, new object[] { keyString });
break;
}
}
else
{

View File

@@ -54,8 +54,7 @@ namespace System.Runtime.Serialization.Json
{
collectionContract.IncrementCollectionCount(jsonWriter, obj, context);
Type enumeratorReturnType;
IEnumerator enumerator = collectionContract.GetEnumeratorForCollection(obj, out enumeratorReturnType);
IEnumerator enumerator = collectionContract.GetEnumeratorForCollection(obj);
bool canWriteSimpleDictionary = collectionContract.Kind == CollectionKind.GenericDictionary
|| collectionContract.Kind == CollectionKind.Dictionary;
@@ -65,6 +64,8 @@ namespace System.Runtime.Serialization.Json
if (canWriteSimpleDictionary && useSimpleDictionaryFormat)
{
ReflectionWriteObjectAttribute(jsonWriter);
Type[] itemTypeGenericArguments = collectionContract.ItemType.GetGenericArguments();
Type dictionaryValueType = itemTypeGenericArguments.Length == 2 ? itemTypeGenericArguments[1] : null;
while (enumerator.MoveNext())
{
@@ -72,7 +73,7 @@ namespace System.Runtime.Serialization.Json
object key = ((IKeyValue)current).Key;
object value = ((IKeyValue)current).Value;
_reflectionClassWriter.ReflectionWriteStartElement(jsonWriter, key.ToString());
_reflectionClassWriter.ReflectionWriteValue(jsonWriter, context, value.GetType(), value, false, primitiveContractForParamType: null);
_reflectionClassWriter.ReflectionWriteValue(jsonWriter, context, dictionaryValueType ?? value.GetType(), value, false, primitiveContractForParamType: null);
_reflectionClassWriter.ReflectionWriteEndElement(jsonWriter);
}
}
@@ -80,7 +81,7 @@ namespace System.Runtime.Serialization.Json
{
ReflectionWriteArrayAttribute(jsonWriter);
PrimitiveDataContract primitiveContractForType = PrimitiveDataContract.GetPrimitiveDataContract(enumeratorReturnType);
PrimitiveDataContract primitiveContractForType = PrimitiveDataContract.GetPrimitiveDataContract(collectionContract.UnderlyingType);
if (primitiveContractForType != null && primitiveContractForType.UnderlyingType != Globals.TypeOfObject)
{
while (enumerator.MoveNext())
@@ -92,7 +93,17 @@ namespace System.Runtime.Serialization.Json
}
else
{
Type elementType = collectionContract.GetCollectionElementType();
bool isDictionary = collectionContract.Kind == CollectionKind.Dictionary || collectionContract.Kind == CollectionKind.GenericDictionary;
DataContract itemContract = null;
JsonDataContract jsonDataContract = null;
if (isDictionary)
{
itemContract = XmlObjectSerializerWriteContextComplexJson.GetRevisedItemContract(collectionContract.ItemContract);
jsonDataContract = JsonDataContract.GetJsonDataContract(itemContract);
}
while (enumerator.MoveNext())
{
object current = enumerator.Current;
@@ -100,14 +111,11 @@ namespace System.Runtime.Serialization.Json
_reflectionClassWriter.ReflectionWriteStartElement(jsonWriter, itemName);
if (isDictionary)
{
var itemContract = XmlObjectSerializerWriteContextComplexJson.GetRevisedItemContract(collectionContract.ItemContract);
var jsonDataContract = JsonDataContract.GetJsonDataContract(itemContract);
jsonDataContract.WriteJsonValue(jsonWriter, current, context, collectionContract.ItemType.TypeHandle);
}
else
{
_reflectionClassWriter.ReflectionWriteValue(jsonWriter, context, enumeratorReturnType, current, false, primitiveContractForParamType: null);
_reflectionClassWriter.ReflectionWriteValue(jsonWriter, context, elementType, current, false, primitiveContractForParamType: null);
}
_reflectionClassWriter.ReflectionWriteEndElement(jsonWriter);

View File

@@ -458,7 +458,7 @@ namespace System.Runtime.Serialization
}
else
{
ConstructorInfo ci = collectionContract.UnderlyingType.GetConstructor(Array.Empty<Type>());
ConstructorInfo ci = collectionContract.Constructor;
object newCollection = ci.Invoke(Array.Empty<object>());
return newCollection;
}
@@ -507,15 +507,29 @@ namespace System.Runtime.Serialization
Func<object, object> objectToKeyValuePairGetKey = (Func<object, object>)s_objectToKeyValuePairGetKey.MakeGenericMethod(keyType, valueType).CreateDelegate(typeof(Func<object, object>));
Func<object, object> objectToKeyValuePairGetValue = (Func<object, object>)s_objectToKeyValuePairGetValue.MakeGenericMethod(keyType, valueType).CreateDelegate(typeof(Func<object, object>));
return (resultCollection, collectionItem, index) =>
if (collectionContract.Kind == CollectionKind.GenericDictionary)
{
object key = objectToKeyValuePairGetKey(collectionItem);
object value = objectToKeyValuePairGetValue(collectionItem);
return (resultCollection, collectionItem, index) =>
{
object key = objectToKeyValuePairGetKey(collectionItem);
object value = objectToKeyValuePairGetValue(collectionItem);
IDictionary dict = (IDictionary)resultCollection;
dict.Add(key, value);
return resultCollection;
};
collectionContract.AddMethod.Invoke(resultCollection, new object[] { key, value });
return resultCollection;
};
}
else
{
return (resultCollection, collectionItem, index) =>
{
object key = objectToKeyValuePairGetKey(collectionItem);
object value = objectToKeyValuePairGetValue(collectionItem);
IDictionary dict = (IDictionary)resultCollection;
dict.Add(key, value);
return resultCollection;
};
}
}
else
{
@@ -540,7 +554,7 @@ namespace System.Runtime.Serialization
}
else
{
MethodInfo addMethod = collectionType.GetMethod("Add");
MethodInfo addMethod = collectionContract.AddMethod;
if (addMethod == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.CollectionMustHaveAddMethod, DataContract.GetClrTypeFullName(collectionContract.UnderlyingType))));

View File

@@ -50,9 +50,8 @@ namespace System.Runtime.Serialization
{
collectionDataContract.IncrementCollectionCount(xmlWriter, obj, context);
Type enumeratorReturnType;
IEnumerator enumerator = collectionDataContract.GetEnumeratorForCollection(obj, out enumeratorReturnType);
PrimitiveDataContract primitiveContractForType = PrimitiveDataContract.GetPrimitiveDataContract(enumeratorReturnType);
IEnumerator enumerator = collectionDataContract.GetEnumeratorForCollection(obj);
PrimitiveDataContract primitiveContractForType = PrimitiveDataContract.GetPrimitiveDataContract(collectionDataContract.UnderlyingType);
if (primitiveContractForType != null && primitiveContractForType.UnderlyingType != Globals.TypeOfObject)
{
@@ -65,19 +64,20 @@ namespace System.Runtime.Serialization
}
else
{
Type elementType = collectionDataContract.GetCollectionElementType();
bool isDictionary = collectionDataContract.Kind == CollectionKind.Dictionary || collectionDataContract.Kind == CollectionKind.GenericDictionary;
while (enumerator.MoveNext())
{
object current = enumerator.Current;
context.IncrementItemCount(1);
_reflectionClassWriter.ReflectionWriteStartElement(xmlWriter, enumeratorReturnType, ns, ns.Value, itemName.Value, 0);
_reflectionClassWriter.ReflectionWriteStartElement(xmlWriter, elementType, ns, ns.Value, itemName.Value, 0);
if (isDictionary)
{
collectionDataContract.ItemContract.WriteXmlValue(xmlWriter, current, context);
}
else
{
_reflectionClassWriter.ReflectionWriteValue(xmlWriter, context, enumeratorReturnType, current, false, primitiveContractForParamType: null);
_reflectionClassWriter.ReflectionWriteValue(xmlWriter, context, elementType, current, false, primitiveContractForParamType: null);
}
_reflectionClassWriter.ReflectionWriteEndElement(xmlWriter);

View File

@@ -103,7 +103,7 @@ namespace System.Runtime.Serialization
{
if (s_ienumeratorGetCurrentMethod == null)
{
s_ienumeratorGetCurrentMethod = typeof(IEnumerator).GetProperty("Current").GetMethod;
s_ienumeratorGetCurrentMethod = typeof(IEnumerator).GetProperty("Current").GetGetMethod();
Debug.Assert(s_ienumeratorGetCurrentMethod != null);
}
return s_ienumeratorGetCurrentMethod;