示例#1
0
 object?GetReadDictionaryItemDelegate(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context, CollectionDataContract collectionContract, Type itemType, string itemName, string itemNs)
 {
     return(ReflectionReadDictionaryItem(xmlReader, context, collectionContract));
 };
示例#2
0
 public bool TryReadInt64Array(XmlObjectSerializerReadContext context,
示例#3
0
 public bool TryReadDoubleArray(XmlObjectSerializerReadContext context,
示例#4
0
 public bool TryReadBooleanArray(XmlObjectSerializerReadContext context,
示例#5
0
 public bool TryReadDecimalArray(XmlObjectSerializerReadContext context,
示例#6
0
 public override object ReadXmlValue(XmlReaderDelegator reader, XmlObjectSerializerReadContext context)
 {
     throw new NotImplementedException();
 }
示例#7
0
 public virtual bool TryReadDateTimeArray(XmlObjectSerializerReadContext context,
示例#8
0
        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);
        }
示例#9
0
 internal ExtensionDataReader(XmlObjectSerializerReadContext context)
 {
     _attributeIndex = -1;
     _context        = context;
 }
示例#10
0
 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));
 }
示例#11
0
        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;
                    });
                }
            }
        }
示例#12
0
 protected virtual bool ReflectionReadSpecialCollection(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context, CollectionDataContract collectionContract, object resultCollection)
 {
     return(false);
 }
示例#13
0
 protected abstract object ReflectionReadDictionaryItem(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context, CollectionDataContract collectionContract);
示例#14
0
 protected abstract void ReflectionReadMembers(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context, XmlDictionaryString[] memberNames, XmlDictionaryString[] memberNamespaces, ClassDataContract classContract, ref object obj);
示例#15
0
 public object ReflectionReadCollection(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context, XmlDictionaryString collectionItemName, XmlDictionaryString collectionItemNamespace, CollectionDataContract collectionContract)
 {
     return(ReflectionReadCollectionCore(xmlReader, context, collectionItemName, collectionItemNamespace, collectionContract));
 }
示例#16
0
 private void CheckExpectedArrayLength(XmlObjectSerializerReadContext context, int arrayLength)
 {
     context.IncrementItemCount(arrayLength);
 }
示例#17
0
 protected object HandleReadValue(object obj, XmlObjectSerializerReadContext context)
 {
     context.AddNewObject(obj);
     return(obj);
 }
示例#18
0
 protected int GetArrayLengthQuota(XmlObjectSerializerReadContext context)
 {
     return(Math.Min(context.RemainingItemCount, int.MaxValue));
 }
示例#19
0
 public override object ReadXmlValue(XmlReaderDelegator reader, XmlObjectSerializerReadContext context)
 {
     return((context == null) ? reader.ReadElementContentAsGuid()
         : HandleReadValue(reader.ReadElementContentAsGuid(), context));
 }
示例#20
0
 public override object ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
 {
     throw CreateInvalidDataContractException();
 }