Commit 671419c3 authored by Marcell Toth's avatar Marcell Toth Committed by Nick Craver

Make DapperRow implement IReadOnlyDictionary<string, object> (#913)

parent bff5e750
......@@ -10,6 +10,7 @@ public static partial class SqlMapper
private sealed class DapperRow
: System.Dynamic.IDynamicMetaObjectProvider
, IDictionary<string, object>
, IReadOnlyDictionary<string, object>
{
private readonly DapperTable table;
private object[] values;
......@@ -208,6 +209,41 @@ private object SetValue(string key, object value, bool isAdd)
}
#endregion
#region Implementation of IReadOnlyDictionary<string,object>
int IReadOnlyCollection<KeyValuePair<string, object>>.Count
{
get
{
return values.Count(t => !(t is DeadValue));
}
}
bool IReadOnlyDictionary<string, object>.ContainsKey(string key)
{
int index = table.IndexOfName(key);
return index >= 0 && index < values.Length && !(values[index] is DeadValue);
}
object IReadOnlyDictionary<string, object>.this[string key]
{
get { TryGetValue(key, out object val); return val; }
}
IEnumerable<string> IReadOnlyDictionary<string, object>.Keys
{
get { return this.Select(kv => kv.Key); }
}
IEnumerable<object> IReadOnlyDictionary<string, object>.Values
{
get { return this.Select(kv => kv.Value); }
}
#endregion
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment