Interface IXunitSerializer
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
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
typeTypeThe type of the value
valueobjectThe value to test
failureReasonstringReturns a failure reason when the value isn't serializable
Returns
- bool
Return
trueif 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
valueobjectThe 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.