Exemple #1
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);
        }
        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);
        }
Exemple #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);
        }
Exemple #4
0
        private void AddClassDataContract(ClassDataContract classDataContract)
        {
            if (classDataContract.BaseContract != null)
            {
                Add(classDataContract.BaseContract.StableName, classDataContract.BaseContract);
            }
            if (!classDataContract.IsISerializable)
            {
                if (classDataContract.Members != null)
                {
                    for (int i = 0; i < classDataContract.Members.Count; i++)
                    {
                        DataMember   dataMember         = classDataContract.Members[i];
                        DataContract memberDataContract = GetMemberTypeDataContract(dataMember);
#if SUPPORT_SURROGATE
                        if (_dataContractSurrogate != null && dataMember.MemberInfo != null)
                        {
                            object customData = DataContractSurrogateCaller.GetCustomDataToExport(
                                _dataContractSurrogate,
                                dataMember.MemberInfo,
                                memberDataContract.UnderlyingType);
                            if (customData != null)
                            {
                                SurrogateDataTable.Add(dataMember, customData);
                            }
                        }
#endif
                        Add(memberDataContract.StableName, memberDataContract);
                    }
                }
            }
            AddKnownDataContracts(classDataContract.KnownDataContracts);
        }
 private void AddClassDataContract(ClassDataContract classDataContract)
 {
     if (classDataContract.BaseContract != null)
     {
         this.Add(classDataContract.BaseContract.StableName, classDataContract.BaseContract);
     }
     if (!classDataContract.IsISerializable && (classDataContract.Members != null))
     {
         for (int i = 0; i < classDataContract.Members.Count; i++)
         {
             DataMember   dataMember             = classDataContract.Members[i];
             DataContract memberTypeDataContract = this.GetMemberTypeDataContract(dataMember);
             if ((this.dataContractSurrogate != null) && (dataMember.MemberInfo != null))
             {
                 object obj2 = DataContractSurrogateCaller.GetCustomDataToExport(this.dataContractSurrogate, dataMember.MemberInfo, memberTypeDataContract.UnderlyingType);
                 if (obj2 != null)
                 {
                     this.SurrogateDataTable.Add(dataMember, obj2);
                 }
             }
             this.Add(memberTypeDataContract.StableName, memberTypeDataContract);
         }
     }
     this.AddKnownDataContracts(classDataContract.KnownDataContracts);
 }
        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));
 }
Exemple #8
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);
        }
Exemple #10
0
        internal static object?SurrogateToDataContractType(ISerializationSurrogateProvider serializationSurrogateProvider, object?oldObj, Type surrogatedDeclaredType, ref Type objType)
        {
            object?obj = DataContractSurrogateCaller.GetObjectToSerialize(serializationSurrogateProvider, oldObj, objType, surrogatedDeclaredType);

            if (obj != oldObj)
            {
                objType = obj != null?obj.GetType() : Globals.TypeOfObject;
            }
            return(obj);
        }
        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);
        }
Exemple #12
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));
        }
Exemple #13
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));
        }
        internal static object SurrogateToDataContractType(IDataContractSurrogate dataContractSurrogate, object oldObj, Type surrogatedDeclaredType, ref Type objType)
        {
            object obj2 = DataContractSurrogateCaller.GetObjectToSerialize(dataContractSurrogate, oldObj, objType, surrogatedDeclaredType);

            if (obj2 != oldObj)
            {
                if (obj2 == null)
                {
                    objType = Globals.TypeOfObject;
                    return(obj2);
                }
                objType = obj2.GetType();
            }
            return(obj2);
        }
        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 #16
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));
        }
Exemple #18
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);
        }
Exemple #21
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);
        }
Exemple #22
0
 internal static Type GetSurrogatedType(IDataContractSurrogate dataContractSurrogate, Type type)
 {
     return(DataContractSurrogateCaller.GetDataContractType(dataContractSurrogate, DataContract.UnwrapNullableType(type)));
 }
Exemple #23
0
 internal static Type GetSurrogatedType(ISerializationSurrogateProvider serializationSurrogateProvider, Type type)
 {
     return(DataContractSurrogateCaller.GetDataContractType(serializationSurrogateProvider, DataContract.UnwrapNullableType(type)));
 }