You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Build a strategy-based implementation of ISerializer. In the lines of DelegatedSerializer : ISerializer
It's to be built at the root package Greentube.Serialization.
This will allow consumer to easily plug their implementation.
Something like as:
new DelegatedSerializer(FutureSerializer.Serialize, FutureSerializer.Deserialize);
The DependencyInjection package would expose an easy way in, like: .AddDelegated(a,b).
Proposed API:
/// <summary>/// Delegates the serialization calls to a strategy/// </summary>/// <inheritdoc />publicclassDelegatedSerializer:ISerializer{privatereadonlyFunc<Type,byte[],object>_deserialize;privatereadonlyFunc<Type,object,byte[]>_serialize;/// <inheritdoc />publicDelegatedSerializer(Func<Type,byte[],object>deserialize,Func<Type,object,byte[]>serialize){_deserialize=deserialize??thrownew ArgumentNullException(nameof(deserialize));_serialize=serialize??thrownew ArgumentNullException(nameof(serialize));}/// <inheritdoc />publicbyte[]Serialize<T>(T@object)=> _serialize(typeof(T), @object);/// <inheritdoc />publicobjectDeserialize(Typetype,byte[]bytes)=> _deserialize(type, bytes);}
The reason I proposed providing typeof(T) instead of relying on @object.GetType() on the serialization func is that the generic argument provided could be different than the actual instance. Therefore the information should be passed to the strategy.
The text was updated successfully, but these errors were encountered:
Build a strategy-based implementation of ISerializer. In the lines of
DelegatedSerializer : ISerializer
It's to be built at the root package
Greentube.Serialization
.This will allow consumer to easily plug their implementation.
Something like as:
new DelegatedSerializer(FutureSerializer.Serialize, FutureSerializer.Deserialize);
The DependencyInjection package would expose an easy way in, like: .AddDelegated(a,b).
Proposed API:
The reason I proposed providing typeof(T) instead of relying on @object.GetType() on the serialization func is that the generic argument provided could be different than the actual instance. Therefore the information should be passed to the strategy.
The text was updated successfully, but these errors were encountered: