Table of Contents

Interface IXunitSerializer

Namespace
Xunit.Sdk

Implemented by types which can support serialization and deserialization. This allows external serializers for types which would be inconvenient or impossible to implement IXunitSerializable directly.

public interface IXunitSerializer
Extension Methods

Methods

Deserialize(Type, string)

Deserializes a value that was obtained from Serialize(object).

object Deserialize(Type type, string serializedValue)

Parameters

type Type

The type of the original value

serializedValue string

The serialized value

Returns

object

The deserialized value

IsSerializable(Type, object?, out string?)

Determines if a specific value of data is serializable.

bool IsSerializable(Type type, object? value, out string? failureReason)

Parameters

type Type

The type of the value

value object

The value to test

failureReason string

Returns a failure reason when the value isn't serializable

Returns

bool

Return true if the value is serializable; false, otherwise

Remarks

This will be called by IsSerializable(object?), IsSerializable(object?, Type?), and Serialize(object?, Type?). The failure reason is used when called from Serialize to format an error exception, but is otherwise ignored from the calls from IsSerializable.

The type of value may not directly match type, as the type is derived from unwrapping nullability and array element types, so use care when looking at the value to determine serializability.

Serialize(object)

Serializes a value into a string to be later deserialized with Deserialize(Type, string).

string Serialize(object value)

Parameters

value object

The value to be serialized

Returns

string

The serialized value

Remarks

This method will never be called with null values, because those are already special cased by the serialization system. You may assume that IsSerializable(Type, object?, out string?) is called before this, so any validation done there need not be repeated here.