object?GetReadDictionaryItemDelegate(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context, CollectionDataContract collectionContract, Type itemType, string itemName, string itemNs) { return(ReflectionReadDictionaryItem(xmlReader, context, collectionContract)); };
public bool TryReadInt64Array(XmlObjectSerializerReadContext context,
public bool TryReadDoubleArray(XmlObjectSerializerReadContext context,
public bool TryReadBooleanArray(XmlObjectSerializerReadContext context,
public bool TryReadDecimalArray(XmlObjectSerializerReadContext context,
public override object ReadXmlValue(XmlReaderDelegator reader, XmlObjectSerializerReadContext context) { throw new NotImplementedException(); }
public virtual bool TryReadDateTimeArray(XmlObjectSerializerReadContext context,
private bool ReflectionTryReadPrimitiveArray(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context, XmlDictionaryString collectionItemName, XmlDictionaryString collectionItemNamespace, Type type, Type itemType, int arraySize, out object resultArray) { resultArray = null; PrimitiveDataContract primitiveContract = PrimitiveDataContract.GetPrimitiveDataContract(itemType); if (primitiveContract == null) { return(false); } switch (itemType.GetTypeCode()) { case TypeCode.Boolean: { bool[] boolArray = null; xmlReader.TryReadBooleanArray(context, collectionItemName, collectionItemNamespace, arraySize, out boolArray); resultArray = boolArray; } break; case TypeCode.DateTime: { DateTime[] dateTimeArray = null; xmlReader.TryReadDateTimeArray(context, collectionItemName, collectionItemNamespace, arraySize, out dateTimeArray); resultArray = dateTimeArray; } break; case TypeCode.Decimal: { decimal[] decimalArray = null; xmlReader.TryReadDecimalArray(context, collectionItemName, collectionItemNamespace, arraySize, out decimalArray); resultArray = decimalArray; } break; case TypeCode.Int32: { int[] intArray = null; xmlReader.TryReadInt32Array(context, collectionItemName, collectionItemNamespace, arraySize, out intArray); resultArray = intArray; } break; case TypeCode.Int64: { long[] longArray = null; xmlReader.TryReadInt64Array(context, collectionItemName, collectionItemNamespace, arraySize, out longArray); resultArray = longArray; } break; case TypeCode.Single: { float[] floatArray = null; xmlReader.TryReadSingleArray(context, collectionItemName, collectionItemNamespace, arraySize, out floatArray); resultArray = floatArray; } break; case TypeCode.Double: { double[] doubleArray = null; xmlReader.TryReadDoubleArray(context, collectionItemName, collectionItemNamespace, arraySize, out doubleArray); resultArray = doubleArray; } break; default: return(false); } return(true); }
internal ExtensionDataReader(XmlObjectSerializerReadContext context) { _attributeIndex = -1; _context = context; }
private object ReflectionInternalDeserialize(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context, CollectionDataContract collectionContract, Type type, string name, string ns) { return(context.InternalDeserialize(xmlReader, DataContract.GetId(type.TypeHandle), type.TypeHandle, name, ns)); }
private CollectionSetItemDelegate GetCollectionSetItemDelegate <T>(CollectionDataContract collectionContract, object resultCollectionObject, bool isReadOnlyCollection) { if (isReadOnlyCollection && collectionContract.Kind == CollectionKind.Array) { int arraySize = ((Array)resultCollectionObject).Length; return((resultCollection, collectionItem, index) => { if (index == arraySize) { XmlObjectSerializerReadContext.ThrowArrayExceededSizeException(arraySize, collectionContract.UnderlyingType); } ((T[])resultCollection)[index] = (T)collectionItem; return resultCollection; }); } else if (!isReadOnlyCollection && IsArrayLikeCollection(collectionContract)) { return((resultCollection, collectionItem, index) => { resultCollection = XmlObjectSerializerReadContext.EnsureArraySize((T[])resultCollection, index); ((T[])resultCollection)[index] = (T)collectionItem; return resultCollection; }); } else if (collectionContract.Kind == CollectionKind.GenericDictionary || collectionContract.Kind == CollectionKind.Dictionary) { Type keyType = collectionContract.ItemType.GenericTypeArguments[0]; Type valueType = collectionContract.ItemType.GenericTypeArguments[1]; 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) => { object key = objectToKeyValuePairGetKey(collectionItem); object value = objectToKeyValuePairGetValue(collectionItem); IDictionary dict = (IDictionary)resultCollection; dict.Add(key, value); return resultCollection; }); } else { Type collectionType = resultCollectionObject.GetType(); Type genericCollectionType = typeof(ICollection <T>); Type typeIList = Globals.TypeOfIList; if (genericCollectionType.IsAssignableFrom(collectionType)) { return((resultCollection, collectionItem, index) => { ((ICollection <T>)resultCollection).Add((T)collectionItem); return resultCollection; }); } else if (typeIList.IsAssignableFrom(collectionType)) { return((resultCollection, collectionItem, index) => { ((IList)resultCollection).Add(collectionItem); return resultCollection; }); } else { MethodInfo addMethod = collectionType.GetMethod("Add"); if (addMethod == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.CollectionMustHaveAddMethod, DataContract.GetClrTypeFullName(collectionContract.UnderlyingType)))); } return((resultCollection, collectionItem, index) => { addMethod.Invoke(resultCollection, new object[] { collectionItem }); return resultCollection; }); } } }
protected virtual bool ReflectionReadSpecialCollection(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context, CollectionDataContract collectionContract, object resultCollection) { return(false); }
protected abstract object ReflectionReadDictionaryItem(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context, CollectionDataContract collectionContract);
protected abstract void ReflectionReadMembers(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context, XmlDictionaryString[] memberNames, XmlDictionaryString[] memberNamespaces, ClassDataContract classContract, ref object obj);
public object ReflectionReadCollection(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context, XmlDictionaryString collectionItemName, XmlDictionaryString collectionItemNamespace, CollectionDataContract collectionContract) { return(ReflectionReadCollectionCore(xmlReader, context, collectionItemName, collectionItemNamespace, collectionContract)); }
private void CheckExpectedArrayLength(XmlObjectSerializerReadContext context, int arrayLength) { context.IncrementItemCount(arrayLength); }
protected object HandleReadValue(object obj, XmlObjectSerializerReadContext context) { context.AddNewObject(obj); return(obj); }
protected int GetArrayLengthQuota(XmlObjectSerializerReadContext context) { return(Math.Min(context.RemainingItemCount, int.MaxValue)); }
public override object ReadXmlValue(XmlReaderDelegator reader, XmlObjectSerializerReadContext context) { return((context == null) ? reader.ReadElementContentAsGuid() : HandleReadValue(reader.ReadElementContentAsGuid(), context)); }
public override object ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context) { throw CreateInvalidDataContractException(); }