Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrap all messages saved to the store in WrappedValue so that stores t…
…hat need to serialize the input can do so using ToString.
- Loading branch information
Showing
4 changed files
with
62 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
namespace SignalR.MessageBus | ||
{ | ||
/// <summary> | ||
/// All values saved to the messages store are wrapped by this type. | ||
/// If a store needs to save values in a serializable way then it just needs to call | ||
/// ToString() and we'll unwrap it when it comes back (if needed). | ||
/// </summary> | ||
internal class WrappedValue | ||
{ | ||
private readonly IJsonSerializer _serializer; | ||
private readonly object _value; | ||
|
||
public WrappedValue(object value, IJsonSerializer serializer) | ||
{ | ||
_value = value; | ||
_serializer = serializer; | ||
} | ||
|
||
public object Value | ||
{ | ||
get | ||
{ | ||
return _value; | ||
} | ||
} | ||
|
||
public static T Unwrap<T>(object value, IJsonSerializer serializer) | ||
{ | ||
var wrappedValue = value as WrappedValue; | ||
if (wrappedValue != null) | ||
{ | ||
return (T)wrappedValue.Value; | ||
} | ||
|
||
return serializer.Parse<T>((string)value); | ||
} | ||
|
||
public static object Unwrap(object value, IJsonSerializer serializer) | ||
{ | ||
var wrappedValue = value as WrappedValue; | ||
if (wrappedValue != null) | ||
{ | ||
return wrappedValue.Value; | ||
} | ||
|
||
return serializer.Parse((string)value); | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return _serializer.Stringify(_value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters