Class AsyncAsSyncSerializerExtensionMethods
Extension methods for adapting an IAsyncSerializer<T> to work as a synchronous ISerializer<T>.
public static class AsyncAsSyncSerializerExtensionMethods
- Inheritance
-
AsyncAsSyncSerializerExtensionMethods
- Inherited Members
Methods
AsSyncOverAsync<T>(IAsyncSerializer<T>)
Adapts an IAsyncSerializer<T> to work as a synchronous ISerializer<T>. This allows async serializer implementations to be used in synchronous contexts.
public static ISerializer<T> AsSyncOverAsync<T>(this IAsyncSerializer<T> serializer)
Parameters
serializerIAsyncSerializer<T>The async serializer to adapt.
Returns
- ISerializer<T>
A synchronous ISerializer<T> that wraps the async serializer. The returned instance also implements IDisposable.
Type Parameters
TThe type of object to be serialized.
Remarks
The returned instance implements IDisposable. When disposed, it will:
- Cancel any in-flight serialization operations
- Dispose the wrapped async serializer if it implements IDisposable
Important: Avoid disposing the wrapped async serializer independently while the sync wrapper is still in use, as this may cause unexpected exceptions during serialization.