Add ISource to handle IReadOnlyDictionary<TKey, TValue> #342
-
Is your feature request related to a problem? Please describe. Describe alternatives you've considered |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
You're saying that this tests fails for SmartFormat v3.2.1? [Test]
public void ReadOnlyDictionaryTest()
{
var dict = new Dictionary<string, object> { { "One", 1 }, { "Two", 2 }, { "Three", 3 }, };
var roDict = new ReadOnlyDictionary<string, object>(dict);
var formatter = Smart.CreateDefaultSmartFormat();
var result = formatter.Format("{One}{Two}{Three}", roDict);
Assert.That(result, Is.EqualTo("123"));
} |
Beta Was this translation helpful? Give feedback.
-
public class CustomReadOnlyDictionary<TKey, TValue> : IReadOnlyDictionary<TKey, TValue>
{
private readonly IDictionary<TKey, TValue> _dictionary;
public CustomReadOnlyDictionary(IDictionary<TKey, TValue> dictionary)
{
_dictionary = dictionary;
}
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
{
return _dictionary.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public int Count => _dictionary.Count;
public bool ContainsKey(TKey key)
{
return _dictionary.ContainsKey(key);
}
public bool TryGetValue(TKey key, out TValue value)
{
return _dictionary.TryGetValue(key, out value);
}
public TValue this[TKey key] => _dictionary[key];
public IEnumerable<TKey> Keys => _dictionary.Keys;
public IEnumerable<TValue> Values => _dictionary.Values;
}
var roDict = new CustomReadOnlyDictionary<string, object>(new Dictionary<string, object> { { "One", 1 }, { "Two", 2 }, { "Three", 3 }, });
var formatter = Smart.CreateDefaultSmartFormat();
var result = formatter.Format("{One}{Two}{Three}", roDict);
Assert.That(result, Is.EqualTo("123")); This should succeed, but does not in any |
Beta Was this translation helpful? Give feedback.
You're saying that this tests fails for SmartFormat v3.2.1?