diff --git a/src/Microsoft.AspNet.PipelineCore/Collections/ItemsDictionary.cs b/src/Microsoft.AspNet.PipelineCore/Collections/ItemsDictionary.cs new file mode 100644 index 0000000000..5f4abca7c0 --- /dev/null +++ b/src/Microsoft.AspNet.PipelineCore/Collections/ItemsDictionary.cs @@ -0,0 +1,111 @@ +using System.Collections; +using System.Collections.Generic; +using Microsoft.AspNet.Abstractions; + +namespace Microsoft.AspNet.PipelineCore +{ + public class ItemsDictionary : IDictionary + { + public ItemsDictionary() + : this(new Dictionary()) + { + } + + public ItemsDictionary(IDictionary items) + { + Items = items; + } + + public IDictionary Items { get; private set; } + + // Replace the indexer with one that returns null for missing values + object IDictionary.this[object key] + { + get + { + object value; + if (Items.TryGetValue(key, out value)) + { + return value; + } + return null; + } + set { Items[key] = value; } + } + + void IDictionary.Add(object key, object value) + { + Items.Add(key, value); + } + + bool IDictionary.ContainsKey(object key) + { + return Items.ContainsKey(key); + } + + ICollection IDictionary.Keys + { + get { return Items.Keys; } + } + + bool IDictionary.Remove(object key) + { + return Items.Remove(key); + } + + bool IDictionary.TryGetValue(object key, out object value) + { + return Items.TryGetValue(key, out value); + } + + ICollection IDictionary.Values + { + get { return Items.Values; } + } + + void ICollection>.Add(KeyValuePair item) + { + Items.Add(item); + } + + void ICollection>.Clear() + { + Items.Clear(); + } + + bool ICollection>.Contains(KeyValuePair item) + { + return Items.Contains(item); + } + + void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex) + { + Items.CopyTo(array, arrayIndex); + } + + int ICollection>.Count + { + get { return Items.Count; } + } + + bool ICollection>.IsReadOnly + { + get { return Items.IsReadOnly; } + } + + bool ICollection>.Remove(KeyValuePair item) + { + return Items.Remove(item); + } + + IEnumerator> IEnumerable>.GetEnumerator() + { + return Items.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return Items.GetEnumerator(); + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.PipelineCore/DefaultCanHasItems.cs b/src/Microsoft.AspNet.PipelineCore/DefaultCanHasItems.cs index 31e41440bb..13513d3653 100644 --- a/src/Microsoft.AspNet.PipelineCore/DefaultCanHasItems.cs +++ b/src/Microsoft.AspNet.PipelineCore/DefaultCanHasItems.cs @@ -6,7 +6,7 @@ namespace Microsoft.AspNet.PipelineCore { public DefaultCanHasItems() { - Items = new Dictionary(); + Items = new ItemsDictionary(); } public IDictionary Items { get; private set; } diff --git a/src/Microsoft.AspNet.PipelineCore/Microsoft.AspNet.PipelineCore.kproj b/src/Microsoft.AspNet.PipelineCore/Microsoft.AspNet.PipelineCore.kproj index 51c55b0566..9cf723fe9e 100644 --- a/src/Microsoft.AspNet.PipelineCore/Microsoft.AspNet.PipelineCore.kproj +++ b/src/Microsoft.AspNet.PipelineCore/Microsoft.AspNet.PipelineCore.kproj @@ -23,6 +23,7 @@ +