Пример #1
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);
 }
Пример #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);
        }
Пример #3
0
 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 (dataContractSurrogate != null && dataMember.MemberInfo != null)
                 {
                     object customData = DataContractSurrogateCaller.GetCustomDataToExport(
                         dataContractSurrogate,
                         dataMember.MemberInfo,
                         memberDataContract.UnderlyingType);
                     if (customData != null)
                     {
                         SurrogateDataTable.Add(dataMember, customData);
                     }
                 }
                 Add(memberDataContract.StableName, memberDataContract);
             }
         }
     }
     AddKnownDataContracts(classDataContract.KnownDataContracts);
 }
Пример #4
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));
        }