#3 - Add Count, Keys, and ContainsKey to IReadableStringCollection
This commit is contained in:
parent
f6f7c30a05
commit
f08b6a8d53
|
|
@ -19,7 +19,22 @@ namespace Microsoft.AspNet.Http
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
string this[string key] { get; }
|
string this[string key] { get; }
|
||||||
|
|
||||||
// Joined
|
/// <summary>
|
||||||
|
/// Gets the number of elements contained in the collection.
|
||||||
|
/// </summary>
|
||||||
|
int Count { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a collection containing the keys.
|
||||||
|
/// </summary>
|
||||||
|
ICollection<string> Keys { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines whether the collection contains an element with the specified key.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
bool ContainsKey(string key);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the associated value from the collection. Multiple values will be merged.
|
/// Get the associated value from the collection. Multiple values will be merged.
|
||||||
|
|
@ -30,8 +45,6 @@ namespace Microsoft.AspNet.Http
|
||||||
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "Re-evaluate later.")]
|
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "Re-evaluate later.")]
|
||||||
string Get(string key);
|
string Get(string key);
|
||||||
|
|
||||||
// Joined
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the associated values from the collection in their original format.
|
/// Get the associated values from the collection in their original format.
|
||||||
/// Returns null if the key is not present.
|
/// Returns null if the key is not present.
|
||||||
|
|
@ -39,7 +52,5 @@ namespace Microsoft.AspNet.Http
|
||||||
/// <param name="key"></param>
|
/// <param name="key"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
IList<string> GetValues(string key);
|
IList<string> GetValues(string key);
|
||||||
|
|
||||||
// Raw
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,23 @@ namespace Microsoft.AspNet.PipelineCore.Collections
|
||||||
|
|
||||||
private IDictionary<string, string[]> Store { get; set; }
|
private IDictionary<string, string[]> Store { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the number of elements contained in the collection.
|
||||||
|
/// </summary>
|
||||||
|
public int Count
|
||||||
|
{
|
||||||
|
get { return Store.Count; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a collection containing the keys.
|
||||||
|
/// </summary>
|
||||||
|
public ICollection<string> Keys
|
||||||
|
{
|
||||||
|
get { return Store.Keys; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the associated value from the collection. Multiple values will be merged.
|
/// Get the associated value from the collection. Multiple values will be merged.
|
||||||
/// Returns null if the key is not present.
|
/// Returns null if the key is not present.
|
||||||
|
|
@ -42,6 +59,16 @@ namespace Microsoft.AspNet.PipelineCore.Collections
|
||||||
get { return Get(key); }
|
get { return Get(key); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines whether the collection contains an element with the specified key.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool ContainsKey(string key)
|
||||||
|
{
|
||||||
|
return Store.ContainsKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the associated value from the collection. Multiple values will be merged.
|
/// Get the associated value from the collection. Multiple values will be merged.
|
||||||
/// Returns null if the key is not present.
|
/// Returns null if the key is not present.
|
||||||
|
|
|
||||||
|
|
@ -18,30 +18,55 @@ namespace Microsoft.AspNet.PipelineCore.Collections
|
||||||
_dictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
_dictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerator<KeyValuePair<string, string[]>> GetEnumerator()
|
|
||||||
{
|
|
||||||
foreach (var pair in _dictionary)
|
|
||||||
{
|
|
||||||
yield return new KeyValuePair<string, string[]>(pair.Key, new[] { pair.Value });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
IEnumerator IEnumerable.GetEnumerator()
|
|
||||||
{
|
|
||||||
return GetEnumerator();
|
|
||||||
}
|
|
||||||
|
|
||||||
public string this[string key]
|
public string this[string key]
|
||||||
{
|
{
|
||||||
get { return Get(key); }
|
get { return Get(key); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the number of elements contained in the collection.
|
||||||
|
/// </summary>
|
||||||
|
public int Count
|
||||||
|
{
|
||||||
|
get { return _dictionary.Count; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a collection containing the keys.
|
||||||
|
/// </summary>
|
||||||
|
public ICollection<string> Keys
|
||||||
|
{
|
||||||
|
get { return _dictionary.Keys; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines whether the collection contains an element with the specified key.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool ContainsKey(string key)
|
||||||
|
{
|
||||||
|
return _dictionary.ContainsKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the associated value from the collection. Multiple values will be merged.
|
||||||
|
/// Returns null if the key is not present.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public string Get(string key)
|
public string Get(string key)
|
||||||
{
|
{
|
||||||
string value;
|
string value;
|
||||||
return _dictionary.TryGetValue(key, out value) ? value : null;
|
return _dictionary.TryGetValue(key, out value) ? value : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the associated values from the collection in their original format.
|
||||||
|
/// Returns null if the key is not present.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public IList<string> GetValues(string key)
|
public IList<string> GetValues(string key)
|
||||||
{
|
{
|
||||||
string value;
|
string value;
|
||||||
|
|
@ -56,6 +81,19 @@ namespace Microsoft.AspNet.PipelineCore.Collections
|
||||||
ParsingHelpers.ParseDelimited(cookiesHeader, SemicolonAndComma, AddCookieCallback, _dictionary);
|
ParsingHelpers.ParseDelimited(cookiesHeader, SemicolonAndComma, AddCookieCallback, _dictionary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerator<KeyValuePair<string, string[]>> GetEnumerator()
|
||||||
|
{
|
||||||
|
foreach (var pair in _dictionary)
|
||||||
|
{
|
||||||
|
yield return new KeyValuePair<string, string[]>(pair.Key, new[] { pair.Value });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator IEnumerable.GetEnumerator()
|
||||||
|
{
|
||||||
|
return GetEnumerator();
|
||||||
|
}
|
||||||
|
|
||||||
private static readonly Action<string, string, object> AddCookieCallback = (name, value, state) =>
|
private static readonly Action<string, string, object> AddCookieCallback = (name, value, state) =>
|
||||||
{
|
{
|
||||||
var dictionary = (IDictionary<string, string>)state;
|
var dictionary = (IDictionary<string, string>)state;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue