/// <summary> /// Gets the logical type to deserialize. /// </summary> /// <remarks> /// This is done by checking the type attributes on the current start element. /// </remarks> /// <exception cref="InvalidOperationException">Thrown if the type attributes are not present.</exception> private LogicalType resolveDeserializingType(XmlReader reader, XmlSerializationReader serialReader, bool soap12) { if (true /* AppDomain.CompatVersion >= AppDomain.Orcas */) { LogicalType type = serialReader.deriveTypeFromTypeAttribute(reader, null); if (type != null && _logicalType.Type.IsAssignableFrom(type.Type)) { return(type); } Accessor accessor = _isEncoded ? _logicalType.TypeAccessor : _logicalType.RootAccessor; if (startElementMatchesAccessor(reader, accessor, soap12)) { return(_logicalType); } throw serialReader.CreateUnknownNodeException(); } else { /* Rogue or earlier */ LogicalType type = serialReader.deriveTypeFromTypeAttribute(reader, null); if (type != null) { return(type); } if (startElementMatchesAccessor(reader, _logicalType.TypeAccessor, soap12)) { return(_logicalType); } type = _reflector.FindType(new XmlQualifiedName(reader.Name, reader.NamespaceURI), _isEncoded); if (type != null) { return(type); } return(_logicalType); } }
/// <summary> /// Checks whether this XmlSerializer can begin deserialization at a given XmlElement. /// </summary> /// <remarks> /// It may return false for types that the serializer can deserialize as part of another type. /// </remarks> public virtual bool CanDeserialize(XmlReader reader) { if (_logicalType == null) { return(false); } if (true /* AppDomain.CompatVersion >= AppDomain.Orcas */) { // Check the type passed to the constructor if (_isEncoded) { if (startElementMatchesAccessor(reader, _logicalType.TypeAccessor, false) || startElementMatchesAccessor(reader, _logicalType.TypeAccessor, true)) { return(true); } } else { if (startElementMatchesAccessor(reader, _logicalType.RootAccessor, false)) { return(true); } } bool soap12; XmlSerializationReader serialReader = initXmlSerializationReader(reader, null, out soap12); LogicalType type = serialReader.deriveTypeFromTypeAttribute(reader, null); if (type != null && _logicalType.Type.IsAssignableFrom(type.Type)) { return(true); } } else { /* Rogue or earlier */ // Check the type passed to the constructor if (startElementMatchesAccessor(reader, _logicalType.TypeAccessor, false)) { return(true); } // Checking extra types is only something we do for backward compatibility if (_extraTypes != null) { for (int typeNdx = 0; typeNdx < _extraTypes.Length; ++typeNdx) { if (startElementMatchesAccessor(reader, _extraTypes[typeNdx].TypeAccessor, false)) { return(true); } } } LogicalType type = _reflector.FindType(new XmlQualifiedName(reader.Name, reader.NamespaceURI), _isEncoded); if (type != null) { return(true); } } return(false); }