internal void InternalAdd(XmlQualifiedName name, DataContract dataContract) { DataContract contract = null; if (this.Contracts.TryGetValue(name, out contract)) { if (!contract.Equals(dataContract)) { if ((dataContract.UnderlyingType == null) || (contract.UnderlyingType == null)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.Runtime.Serialization.SR.GetString("DupContractInDataContractSet", new object[] { dataContract.StableName.Name, dataContract.StableName.Namespace }))); } bool flag = DataContract.GetClrTypeFullName(dataContract.UnderlyingType) == DataContract.GetClrTypeFullName(contract.UnderlyingType); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.Runtime.Serialization.SR.GetString("DupTypeContractInDataContractSet", new object[] { flag?dataContract.UnderlyingType.AssemblyQualifiedName: DataContract.GetClrTypeFullName(dataContract.UnderlyingType), flag ? contract.UnderlyingType.AssemblyQualifiedName : DataContract.GetClrTypeFullName(contract.UnderlyingType), dataContract.StableName.Name, dataContract.StableName.Namespace }))); } } else { this.Contracts.Add(name, dataContract); if (dataContract is ClassDataContract) { this.AddClassDataContract((ClassDataContract)dataContract); } else if (dataContract is CollectionDataContract) { this.AddCollectionDataContract((CollectionDataContract)dataContract); } else if (dataContract is XmlDataContract) { this.AddXmlDataContract((XmlDataContract)dataContract); } } }
bool TryGetReferencedType(XmlQualifiedName stableName, DataContract dataContract, bool useReferencedCollectionTypes, out Type type) { object value; Dictionary <XmlQualifiedName, object> referencedTypes = useReferencedCollectionTypes ? GetReferencedCollectionTypes() : GetReferencedTypes(); if (referencedTypes.TryGetValue(stableName, out value)) { type = value as Type; if (type != null) { return(true); } else { // Throw ambiguous type match exception List <Type> types = (List <Type>)value; StringBuilder errorMessage = new StringBuilder(); bool containsGenericType = false; for (int i = 0; i < types.Count; i++) { Type conflictingType = types[i]; if (!containsGenericType) { containsGenericType = conflictingType.IsGenericTypeDefinition; } errorMessage.AppendFormat("{0}\"{1}\" ", Environment.NewLine, conflictingType.AssemblyQualifiedName); if (dataContract != null) { DataContract other = this.GetDataContract(conflictingType); errorMessage.Append(SR.GetString(((other != null && other.Equals(dataContract)) ? SR.ReferencedTypeMatchingMessage : SR.ReferencedTypeNotMatchingMessage))); } } if (containsGenericType) { throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString( (useReferencedCollectionTypes ? SR.AmbiguousReferencedCollectionTypes1 : SR.AmbiguousReferencedTypes1), errorMessage.ToString()))); } else { throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString( (useReferencedCollectionTypes ? SR.AmbiguousReferencedCollectionTypes3 : SR.AmbiguousReferencedTypes3), XmlConvert.DecodeName(stableName.Name), stableName.Namespace, errorMessage.ToString()))); } } } type = null; return(false); }
internal void InternalAdd(XmlQualifiedName name, DataContract dataContract) { DataContract dataContractInSet = null; if (Contracts.TryGetValue(name, out dataContractInSet)) { if (!dataContractInSet.Equals(dataContract)) { if (dataContract.UnderlyingType == null || dataContractInSet.UnderlyingType == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.DupContractInDataContractSet, dataContract.StableName.Name, dataContract.StableName.Namespace))); } else { bool typeNamesEqual = (DataContract.GetClrTypeFullName(dataContract.UnderlyingType) == DataContract.GetClrTypeFullName(dataContractInSet.UnderlyingType)); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.DupTypeContractInDataContractSet, (typeNamesEqual ? dataContract.UnderlyingType.AssemblyQualifiedName : DataContract.GetClrTypeFullName(dataContract.UnderlyingType)), (typeNamesEqual ? dataContractInSet.UnderlyingType.AssemblyQualifiedName : DataContract.GetClrTypeFullName(dataContractInSet.UnderlyingType)), dataContract.StableName.Name, dataContract.StableName.Namespace))); } } } else { Contracts.Add(name, dataContract); if (dataContract is ClassDataContract) { AddClassDataContract((ClassDataContract)dataContract); } else if (dataContract is CollectionDataContract) { AddCollectionDataContract((CollectionDataContract)dataContract); } else if (dataContract is XmlDataContract) { AddXmlDataContract((XmlDataContract)dataContract); } } }
private bool TryGetReferencedType(XmlQualifiedName stableName, DataContract dataContract, bool useReferencedCollectionTypes, out Type type) { object obj2; Dictionary <XmlQualifiedName, object> dictionary = useReferencedCollectionTypes ? this.GetReferencedCollectionTypes() : this.GetReferencedTypes(); if (dictionary.TryGetValue(stableName, out obj2)) { type = obj2 as Type; if (type != null) { return(true); } List <Type> list = (List <Type>)obj2; StringBuilder builder = new StringBuilder(); bool isGenericTypeDefinition = false; for (int i = 0; i < list.Count; i++) { Type clrType = list[i]; if (!isGenericTypeDefinition) { isGenericTypeDefinition = clrType.IsGenericTypeDefinition; } builder.AppendFormat("{0}\"{1}\" ", Environment.NewLine, clrType.AssemblyQualifiedName); if (dataContract != null) { DataContract contract = this.GetDataContract(clrType); builder.Append(System.Runtime.Serialization.SR.GetString(((contract != null) && contract.Equals(dataContract)) ? "ReferencedTypeMatchingMessage" : "ReferencedTypeNotMatchingMessage")); } } if (isGenericTypeDefinition) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.Runtime.Serialization.SR.GetString(useReferencedCollectionTypes ? "AmbiguousReferencedCollectionTypes1" : "AmbiguousReferencedTypes1", new object[] { builder.ToString() }))); } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.Runtime.Serialization.SR.GetString(useReferencedCollectionTypes ? "AmbiguousReferencedCollectionTypes3" : "AmbiguousReferencedTypes3", new object[] { XmlConvert.DecodeName(stableName.Name), stableName.Namespace, builder.ToString() }))); } type = null; return(false); }