object InternalDeserializeWithSurrogate(XmlReaderDelegator xmlReader, Type declaredType, DataContract surrogateDataContract, string name, string ns)
        {
            if (TD.DCDeserializeWithSurrogateStartIsEnabled())
            {
                TD.DCDeserializeWithSurrogateStart(surrogateDataContract.UnderlyingType.FullName);
            }

            DataContract dataContract = surrogateDataContract ??
                                        GetDataContract(DataContractSurrogateCaller.GetDataContractType(dataContractSurrogate, declaredType));

            if (this.IsGetOnlyCollection && dataContract.UnderlyingType != declaredType)
            {
                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.GetString(SR.SurrogatesWithGetOnlyCollectionsNotSupportedSerDeser,
                                                                                                                                                     DataContract.GetClrTypeFullName(declaredType))));
            }
            ReadAttributes(xmlReader);
            string objectId = GetObjectId();
            object oldObj   = InternalDeserialize(xmlReader, name, ns, declaredType, ref dataContract);
            object obj      = DataContractSurrogateCaller.GetDeserializedObject(dataContractSurrogate, oldObj, dataContract.UnderlyingType, declaredType);

            ReplaceDeserializedObject(objectId, oldObj, obj);

            if (TD.DCDeserializeWithSurrogateStopIsEnabled())
            {
                TD.DCDeserializeWithSurrogateStop();
            }

            return(obj);
        }
        private object InternalDeserializeWithSurrogate(XmlReaderDelegator xmlReader, Type declaredType, DataContract surrogateDataContract, string name, string ns)
        {
            DataContract dataContract = surrogateDataContract ?? base.GetDataContract(DataContractSurrogateCaller.GetDataContractType(this.dataContractSurrogate, declaredType));

            if (this.IsGetOnlyCollection && (dataContract.UnderlyingType != declaredType))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(System.Runtime.Serialization.SR.GetString("SurrogatesWithGetOnlyCollectionsNotSupportedSerDeser", new object[] { DataContract.GetClrTypeFullName(declaredType) })));
            }
            this.ReadAttributes(xmlReader);
            string objectId = base.GetObjectId();
            object obj2     = base.InternalDeserialize(xmlReader, name, ns, declaredType, ref dataContract);
            object newObj   = DataContractSurrogateCaller.GetDeserializedObject(this.dataContractSurrogate, obj2, dataContract.UnderlyingType, declaredType);

            base.ReplaceDeserializedObject(objectId, obj2, newObj);
            return(newObj);
        }
Exemple #3
0
        private object InternalDeserializeWithSurrogate(XmlReaderDelegator xmlReader, Type declaredType, DataContract surrogateDataContract, string name, string ns)
        {
            DataContract dataContract = surrogateDataContract ??
                                        GetDataContract(DataContractSurrogateCaller.GetDataContractType(_serializationSurrogateProvider, declaredType));

            if (this.IsGetOnlyCollection && dataContract.UnderlyingType != declaredType)
            {
                throw /*System.Runtime.Serialization.*/ DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(string.Format(SRSerialization.SurrogatesWithGetOnlyCollectionsNotSupportedSerDeser, DataContract.GetClrTypeFullName(declaredType))));
            }
            ReadAttributes(xmlReader);
            string objectId = GetObjectId();
            object oldObj   = InternalDeserialize(xmlReader, name, ns, ref dataContract);
            object obj      = DataContractSurrogateCaller.GetDeserializedObject(_serializationSurrogateProvider, oldObj, dataContract.UnderlyingType, declaredType);

            ReplaceDeserializedObject(objectId, oldObj, obj);

            return(obj);
        }