public void IncludeType(Type type) { System.Diagnostics.Debug.Assert(null != _serializationReflector, "The XmlSerializationReflector has not been initialized."); _serializationReflector.FindType(type, false /*Encoded*/, _defaultNs); _serializationReflector.ReflectIncludedTypes(); }
/// <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); }