XmlSerializerDeserializeSafeT(XElement, Type) Method

Deserializes an XML content to an instance of T in safe mode.

Definition

Namespace: KGySoft.Serialization.Xml
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 9.0.0-preview.1
C#
public static T DeserializeSafe<T>(
	XElement content,
	params Type[]? expectedCustomTypes
)

Parameters

content  XElement
XML content of the object.
expectedCustomTypes  Type
The natively not supported types that are expected to present in the XML content. If content does not contain any natively not supported types, then this parameter is optional.

Type Parameters

T
The expected type of the result.

Return Value

T
The deserialized instance of T.

Remarks

This method works for the results of the Serialize(Object, XmlSerializationOptions) method.

expectedCustomTypes must be specified if content contains names of natively not supported types.

T is allowed to be an interface or abstract type but if it's different from the actual type of the result, then the actual type also might needed to be included in expectedCustomTypes.

For arrays it is enough to specify the element type and for generic types you can specify the natively not supported generic type definition and generic type arguments separately. If expectedCustomTypes contains constructed generic types, then the generic type definition and the type arguments will be treated as expected types in any combination.

  Tip

See the Remarks section of the XmlSerializer class for the list of the natively supported types.

Exceptions

ArgumentNullExceptioncontent must not be .
NotSupportedExceptionDeserializing an inner type is not supported.
ReflectionExceptionAn inner type cannot be instantiated or serialized XML content is corrupt.
ArgumentExceptionXML content is inconsistent or corrupt.
InvalidOperationExceptioncontent cannot be deserialized in safe mode.

See Also