-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #160 from akkadotnet/dev
v0.9.13 Release
- Loading branch information
Showing
4 changed files
with
181 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
### 0.9.12 January 20 2020 #### | ||
### 0.9.13 February 09 2020 #### | ||
|
||
* Added version tolerance during deserialization. | ||
* Added `ArrayList` and non-generic `IEnumerable` support. | ||
* [Added support for serializing and deserializing `IDictionary<TKey, TValue>`](https://github.com/akkadotnet/Hyperion/pull/156) |
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,135 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace Hyperion.Tests | ||
{ | ||
public class GenericDictionarySerializerTests : TestBase | ||
{ | ||
[Fact] | ||
public void CanSerializeDictionary() | ||
{ | ||
var customDict = new CustomDictionary<string, int>(new Dictionary<string, int>() | ||
{ | ||
["key"] = 1 | ||
}); | ||
SerializeAndAssertEquivalent(customDict); | ||
} | ||
|
||
private void SerializeAndAssertEquivalent<T>(T expected) | ||
{ | ||
Serialize(expected); | ||
Reset(); | ||
var res = Deserialize<T>(); | ||
res.Should().BeEquivalentTo(expected); | ||
AssertMemoryStreamConsumed(); | ||
} | ||
|
||
/// <summary> | ||
/// Just a custom class wrapper for another <see cref="IDictionary{TKey,TValue}"/> | ||
/// </summary> | ||
class CustomDictionary<TKey, TValue> : IDictionary<TKey, TValue> | ||
{ | ||
private readonly IDictionary<TKey, TValue> _dictGeneric; | ||
|
||
/// <summary> | ||
/// For serialization | ||
/// </summary> | ||
public CustomDictionary() : this(new Dictionary<TKey, TValue>()) | ||
{ | ||
} | ||
|
||
public CustomDictionary(Dictionary<TKey, TValue> dict) | ||
{ | ||
_dictGeneric = dict; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator() | ||
{ | ||
return _dictGeneric.GetEnumerator(); | ||
} | ||
|
||
/// <inheritdoc /> | ||
IEnumerator IEnumerable.GetEnumerator() | ||
{ | ||
return ((IEnumerable) _dictGeneric).GetEnumerator(); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public void Add(KeyValuePair<TKey, TValue> item) | ||
{ | ||
_dictGeneric.Add(item); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public void Clear() | ||
{ | ||
_dictGeneric.Clear(); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public bool Contains(KeyValuePair<TKey, TValue> item) | ||
{ | ||
return _dictGeneric.Contains(item); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex) | ||
{ | ||
_dictGeneric.CopyTo(array, arrayIndex); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public bool Remove(KeyValuePair<TKey, TValue> item) | ||
{ | ||
return _dictGeneric.Remove(item); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public int Count => _dictGeneric.Count; | ||
|
||
/// <inheritdoc /> | ||
public bool IsReadOnly => _dictGeneric.IsReadOnly; | ||
|
||
/// <inheritdoc /> | ||
public void Add(TKey key, TValue value) | ||
{ | ||
_dictGeneric.Add(key, value); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public bool ContainsKey(TKey key) | ||
{ | ||
return _dictGeneric.ContainsKey(key); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public bool Remove(TKey key) | ||
{ | ||
return _dictGeneric.Remove(key); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public bool TryGetValue(TKey key, out TValue value) | ||
{ | ||
return _dictGeneric.TryGetValue(key, out value); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public TValue this[TKey key] | ||
{ | ||
get => _dictGeneric[key]; | ||
set => _dictGeneric[key] = value; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public ICollection<TKey> Keys => _dictGeneric.Keys; | ||
|
||
/// <inheritdoc /> | ||
public ICollection<TValue> Values => _dictGeneric.Values; | ||
} | ||
} | ||
} |
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