public void AddXmlTypeName(ContentTypeSerializer serializer) { Type targetType = serializer.TargetType; string xmlTypeName = serializer.XmlTypeName; if (this.xmlNameToType.ContainsKey(xmlTypeName)) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.DuplicateXmlTypeName, new object[] { serializer.GetType().AssemblyQualifiedName, this.xmlNameToType[xmlTypeName].AssemblyQualifiedName, xmlTypeName })); } this.typeToXmlName.Add(targetType, xmlTypeName); this.xmlNameToType.Add(xmlTypeName, targetType); }
private void AddTypeSerializer(ContentTypeSerializer serializer) { if (this.serializerInstances.ContainsKey(serializer.TargetType)) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.DuplicateTypeHandler, new object[] { typeof(ContentTypeSerializer).Name, serializer.GetType().AssemblyQualifiedName, this.serializerInstances[serializer.TargetType].GetType().AssemblyQualifiedName, serializer.TargetType })); } if (serializer.XmlTypeName != null) { this.typeNameHelper.AddXmlTypeName(serializer); } this.serializerInstances.Add(serializer.TargetType, serializer); }
private T ReadRawObjectInternal <T>(ContentSerializerAttribute format, ContentTypeSerializer typeSerializer, object existingInstance) { if (format == null) { throw new ArgumentNullException("format"); } if (typeSerializer == null) { throw new ArgumentNullException("typeSerializer"); } object obj; if (format.FlattenContent) { this.Xml.MoveToContent(); obj = typeSerializer.Deserialize(this, format, existingInstance); } else { if (!this.MoveToElement(format.ElementName)) { throw this.CreateInvalidContentException(Resources.ElementNotFound, new object[] { format.ElementName }); } XmlReader xmlReader = this.xmlReader; if (this.Xml.IsEmptyElement) { this.xmlReader = FakeEmptyElementReader.Instance; } xmlReader.ReadStartElement(); obj = typeSerializer.Deserialize(this, format, existingInstance); if (this.xmlReader == xmlReader) { this.xmlReader.ReadEndElement(); } else { this.xmlReader = xmlReader; } } if (obj == null) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.DeserializerReturnedNull, new object[] { typeSerializer.GetType(), typeSerializer.TargetType })); } if (existingInstance != null && obj != existingInstance) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.DeserializerConstructedNewInstance, new object[] { typeSerializer.GetType(), typeSerializer.TargetType })); } if (!(obj is T)) { throw this.CreateInvalidContentException(Resources.WrongXmlType, new object[] { typeof(T), obj.GetType() }); } return((T)((object)obj)); }