Exemple #1
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);
        }
 internal virtual DataContract GetDataContract(RuntimeTypeHandle typeHandle, Type type)
 {
     if (this.IsGetOnlyCollection)
     {
         return(DataContract.GetGetOnlyCollectionDataContract(DataContract.GetId(typeHandle), typeHandle, type, this.Mode));
     }
     return(DataContract.GetDataContract(typeHandle, type, this.Mode));
 }
 internal virtual DataContract GetDataContract(int id, RuntimeTypeHandle typeHandle)
 {
     if (this.IsGetOnlyCollection)
     {
         return(DataContract.GetGetOnlyCollectionDataContract(id, typeHandle, null, this.Mode));
     }
     return(DataContract.GetDataContract(id, typeHandle, this.Mode));
 }
 internal virtual DataContract GetDataContract(int id, RuntimeTypeHandle typeHandle)
 {
     if (IsGetOnlyCollection)
     {
         return(DataContract.GetGetOnlyCollectionDataContract(id, typeHandle, null /*type*/));
     }
     else
     {
         return(DataContract.GetDataContract(id, typeHandle));
     }
 }
 internal virtual DataContract GetDataContract(RuntimeTypeHandle typeHandle, Type?type)
 {
     if (IsGetOnlyCollection)
     {
         return(DataContract.GetGetOnlyCollectionDataContract(DataContract.GetId(typeHandle), typeHandle, type));
     }
     else
     {
         return(DataContract.GetDataContract(typeHandle, type));
     }
 }
        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));
        }