Commit 1b8d8628 authored by mgravell's avatar mgravell

utility API for treating NameValueEntry[] (from streams) as maps

parent 9cfa0435
...@@ -78,6 +78,38 @@ public static class ExtensionMethods ...@@ -78,6 +78,38 @@ public static class ExtensionMethods
return result; return result;
} }
/// <summary>
/// Create a dictionary from an array of key/value pairs
/// </summary>
/// <param name="pairs">The pairs to convert to a dictionary.</param>
public static Dictionary<string, string> ToStringDictionary(this NameValueEntry[] pairs)
{
if (pairs == null) return null;
var result = new Dictionary<string, string>(pairs.Length, StringComparer.Ordinal);
for (int i = 0; i < pairs.Length; i++)
{
result.Add(pairs[i].name, pairs[i].value);
}
return result;
}
/// <summary>
/// Create a dictionary from an array of NameValueEntry values
/// </summary>
/// <param name="values">The entries to convert to a dictionary.</param>
public static Dictionary<RedisValue, RedisValue> ToDictionary(this NameValueEntry[] values)
{
if (values == null) return null;
var result = new Dictionary<RedisValue, RedisValue>(values.Length);
for (int i = 0; i < values.Length; i++)
{
result.Add(values[i].name, values[i].value);
}
return result;
}
/// <summary> /// <summary>
/// Create a dictionary from an array of key/value pairs /// Create a dictionary from an array of key/value pairs
/// </summary> /// </summary>
......
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