Example #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);
        }
Example #2
0
 internal DataContract GetMemberTypeDataContract(DataMember dataMember)
 {
     if (dataMember.MemberInfo != null)
     {
         Type dataMemberType = dataMember.MemberType;
         if (dataMember.IsGetOnlyCollection)
         {
             if (dataContractSurrogate != null)
             {
                 Type dcType = DataContractSurrogateCaller.GetDataContractType(dataContractSurrogate, dataMemberType);
                 if (dcType != dataMemberType)
                 {
                     throw Fx.Exception.AsError(new InvalidDataContractException(SR.SurrogatesWithGetOnlyCollectionsNotSupported(
                                                                                     DataContract.GetClrTypeFullName(dataMemberType), DataContract.GetClrTypeFullName(dataMember.MemberInfo.DeclaringType), dataMember.MemberInfo.Name)));
                 }
             }
             return(DataContract.GetGetOnlyCollectionDataContract(DataContract.GetId(dataMemberType.TypeHandle), dataMemberType.TypeHandle, dataMemberType, SerializationMode.SharedContract));
         }
         else
         {
             return(GetDataContract(dataMemberType));
         }
     }
     return(dataMember.MemberTypeContract);
 }
Example #3
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));
        }