internal override void CheckIfTypeSerializable(Type memberType, bool isMemberTypeSerializable)
        {
            if (mode == SerializationMode.SharedType && surrogateSelector != null &&
                CheckIfTypeSerializableForSharedTypeMode(memberType))
            {
                return;
            }
            else
            {
                if (dataContractSurrogate != null)
                {
                    while (memberType.IsArray)
                    {
                        memberType = memberType.GetElementType();
                    }
                    memberType = DataContractSurrogateCaller.GetDataContractType(dataContractSurrogate, memberType);
                    if (!DataContract.IsTypeSerializable(memberType))
                    {
                        throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.GetString(SR.TypeNotSerializable, memberType)));
                    }
                    return;
                }
            }

            base.CheckIfTypeSerializable(memberType, isMemberTypeSerializable);
        }
Beispiel #2
0
        internal DataContract GetDataContract(Type clrType)
        {
            if (dataContractSurrogate == null)
            {
                return(DataContract.GetDataContract(clrType));
            }
            DataContract dataContract = DataContract.GetBuiltInDataContract(clrType);

            if (dataContract != null)
            {
                return(dataContract);
            }
            Type dcType = DataContractSurrogateCaller.GetDataContractType(dataContractSurrogate, clrType);

            //if (clrType.IsValueType != dcType.IsValueType)
            //    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.GetString(SR.ValueTypeMismatchInSurrogatedType, dcType, clrType)));
            dataContract = DataContract.GetDataContract(dcType);
            if (!SurrogateDataTable.Contains(dataContract))
            {
                object customData = DataContractSurrogateCaller.GetCustomDataToExport(
                    dataContractSurrogate, clrType, dcType);
                if (customData != null)
                {
                    SurrogateDataTable.Add(dataContract, customData);
                }
            }
            return(dataContract);
        }
Beispiel #3
0
        internal DataContract GetMemberTypeDataContract(DataMember dataMember)
        {
            if (dataMember.MemberInfo != null)
            {
                Type dataMemberType = dataMember.MemberType;
                if (dataMember.IsGetOnlyCollection)
                {
#if SUPPORT_SURROGATE
                    if (_dataContractSurrogate != null)
                    {
                        Type dcType = DataContractSurrogateCaller.GetDataContractType(_dataContractSurrogate, dataMemberType);
                        if (dcType != dataMemberType)
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.GetString(SR.SurrogatesWithGetOnlyCollectionsNotSupported,
                                                                                                                                    DataContract.GetClrTypeFullName(dataMemberType), DataContract.GetClrTypeFullName(dataMember.MemberInfo.DeclaringType), dataMember.MemberInfo.Name)));
                        }
                    }
#endif
                    return(DataContract.GetGetOnlyCollectionDataContract(DataContract.GetId(dataMemberType.TypeHandle), dataMemberType.TypeHandle, dataMemberType, SerializationMode.SharedContract));
                }
                else
                {
                    return(GetDataContract(dataMemberType));
                }
            }
            return(dataMember.MemberTypeContract);
        }
        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);
        }
 internal XmlQualifiedName GetStableName(Type clrType)
 {
     if (this.dataContractSurrogate != null)
     {
         return(DataContract.GetStableName(DataContractSurrogateCaller.GetDataContractType(this.dataContractSurrogate, clrType)));
     }
     return(DataContract.GetStableName(clrType));
 }
Beispiel #6
0
        Type GetSurrogatedType(Type type)
        {
            IDataContractSurrogate dataContractSurrogate;

            if (options != null && (dataContractSurrogate = Options.GetSurrogate()) != null)
            {
                type = DataContractSurrogateCaller.GetDataContractType(dataContractSurrogate, type);
            }
            return(type);
        }
        private Type GetSurrogatedType(Type type)
        {
            IDataContractSurrogate surrogate;

            if ((this.options != null) && ((surrogate = this.Options.GetSurrogate()) != null))
            {
                type = DataContractSurrogateCaller.GetDataContractType(surrogate, type);
            }
            return(type);
        }
        private Type GetSurrogatedType(Type type)
        {
#if SUPPORT_SURROGATE
            IDataContractSurrogate dataContractSurrogate;
            if (options != null && (dataContractSurrogate = Options.GetSurrogate()) != null)
            {
                type = DataContractSurrogateCaller.GetDataContractType(dataContractSurrogate, type);
            }
#endif
            return(type);
        }
Beispiel #9
0
        internal XmlQualifiedName GetStableName(Type clrType)
        {
            if (dataContractSurrogate != null)
            {
                Type dcType = DataContractSurrogateCaller.GetDataContractType(dataContractSurrogate, clrType);

                //if (clrType.IsValueType != dcType.IsValueType)
                //    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.GetString(SR.ValueTypeMismatchInSurrogatedType, dcType, clrType)));
                return(DataContract.GetStableName(dcType));
            }
            return(DataContract.GetStableName(clrType));
        }
Beispiel #10
0
        internal XmlQualifiedName GetStableName(Type clrType)
        {
#if SUPPORT_SURROGATE
            if (_dataContractSurrogate != null)
            {
                Type dcType = DataContractSurrogateCaller.GetDataContractType(_dataContractSurrogate, clrType);

                //if (clrType.IsValueType != dcType.IsValueType)
                //    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.GetString(SR.ValueTypeMismatchInSurrogatedType, dcType, clrType)));
                return(DataContract.GetStableName(dcType));
            }
#endif
            return(DataContract.GetStableName(clrType));
        }
Beispiel #11
0
        internal override void CheckIfTypeSerializable(Type memberType, bool isMemberTypeSerializable)
        {
            if (_serializationSurrogateProvider != null)
            {
                while (memberType.IsArray)
                {
                    memberType = memberType.GetElementType();
                }
                memberType = DataContractSurrogateCaller.GetDataContractType(_serializationSurrogateProvider, memberType);
                if (!DataContract.IsTypeSerializable(memberType))
                {
                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.TypeNotSerializable, memberType)));
                }
                return;
            }

            base.CheckIfTypeSerializable(memberType, isMemberTypeSerializable);
        }
        internal DataContract GetMemberTypeDataContract(DataMember dataMember)
        {
            if (dataMember.MemberInfo == null)
            {
                return(dataMember.MemberTypeContract);
            }
            Type memberType = dataMember.MemberType;

            if (!dataMember.IsGetOnlyCollection)
            {
                return(this.GetDataContract(memberType));
            }
            if ((this.dataContractSurrogate != null) && (DataContractSurrogateCaller.GetDataContractType(this.dataContractSurrogate, memberType) != memberType))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(System.Runtime.Serialization.SR.GetString("SurrogatesWithGetOnlyCollectionsNotSupported", new object[] { DataContract.GetClrTypeFullName(memberType), DataContract.GetClrTypeFullName(dataMember.MemberInfo.DeclaringType), dataMember.MemberInfo.Name })));
            }
            return(DataContract.GetGetOnlyCollectionDataContract(DataContract.GetId(memberType.TypeHandle), memberType.TypeHandle, memberType, SerializationMode.SharedContract));
        }
Beispiel #13
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);
        }
 internal override void CheckIfTypeSerializable(Type memberType, bool isMemberTypeSerializable)
 {
     if (((this.mode != SerializationMode.SharedType) || (this.surrogateSelector == null)) || !this.CheckIfTypeSerializableForSharedTypeMode(memberType))
     {
         if (this.dataContractSurrogate != null)
         {
             while (memberType.IsArray)
             {
                 memberType = memberType.GetElementType();
             }
             memberType = DataContractSurrogateCaller.GetDataContractType(this.dataContractSurrogate, memberType);
             if (!DataContract.IsTypeSerializable(memberType))
             {
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(System.Runtime.Serialization.SR.GetString("TypeNotSerializable", new object[] { memberType })));
             }
         }
         else
         {
             base.CheckIfTypeSerializable(memberType, isMemberTypeSerializable);
         }
     }
 }
        internal DataContract GetDataContract(Type clrType)
        {
            if (this.dataContractSurrogate == null)
            {
                return(DataContract.GetDataContract(clrType));
            }
            DataContract builtInDataContract = DataContract.GetBuiltInDataContract(clrType);

            if (builtInDataContract == null)
            {
                Type dataContractType = DataContractSurrogateCaller.GetDataContractType(this.dataContractSurrogate, clrType);
                builtInDataContract = DataContract.GetDataContract(dataContractType);
                if (!this.SurrogateDataTable.Contains(builtInDataContract))
                {
                    object obj2 = DataContractSurrogateCaller.GetCustomDataToExport(this.dataContractSurrogate, clrType, dataContractType);
                    if (obj2 != null)
                    {
                        this.SurrogateDataTable.Add(builtInDataContract, obj2);
                    }
                }
            }
            return(builtInDataContract);
        }
Beispiel #16
0
        internal DataContract GetDataContract(Type clrType)
        {
#if SUPPORT_SURROGATE
            if (_dataContractSurrogate == null)
            {
                return(DataContract.GetDataContract(clrType));
            }
#endif
            DataContract?dataContract = DataContract.GetBuiltInDataContract(clrType);
            if (dataContract != null)
            {
                return(dataContract);
            }

#if SUPPORT_SURROGATE
            Type dcType = DataContractSurrogateCaller.GetDataContractType(_dataContractSurrogate, clrType);
            if (clrType.IsValueType != dcType.IsValueType)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.GetString(SR.ValueTypeMismatchInSurrogatedType, dcType, clrType)));
            }
#endif
            Type dcType = clrType;
            dataContract = DataContract.GetDataContract(dcType);
#if SUPPORT_SURROGATE
            if (!SurrogateDataTable.Contains(dataContract))
            {
                object customData = DataContractSurrogateCaller.GetCustomDataToExport(
                    _dataContractSurrogate, clrType, dcType);
                if (customData != null)
                {
                    SurrogateDataTable.Add(dataContract, customData);
                }
            }
#endif
            return(dataContract);
        }
Beispiel #17
0
 internal static Type GetSurrogatedType(ISerializationSurrogateProvider serializationSurrogateProvider, Type type)
 {
     return(DataContractSurrogateCaller.GetDataContractType(serializationSurrogateProvider, DataContract.UnwrapNullableType(type)));
 }
Beispiel #18
0
 internal static Type GetSurrogatedType(IDataContractSurrogate dataContractSurrogate, Type type)
 {
     return(DataContractSurrogateCaller.GetDataContractType(dataContractSurrogate, DataContract.UnwrapNullableType(type)));
 }
        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);
        }