From 4f33362ab5bf3b87bb7566e7debad4320e22c766 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Wed, 22 Aug 2018 10:30:25 +1200 Subject: [PATCH] Minor RVD and EndpointMetadataCollection refactors (#708) --- .../EndpointMetadataCollection.cs | 14 +++++------- .../RouteValueDictionary.cs | 22 +++---------------- 2 files changed, 9 insertions(+), 27 deletions(-) diff --git a/src/Microsoft.AspNetCore.Routing.Abstractions/EndpointMetadataCollection.cs b/src/Microsoft.AspNetCore.Routing.Abstractions/EndpointMetadataCollection.cs index ee12d0b8e7..4ca653a8fa 100644 --- a/src/Microsoft.AspNetCore.Routing.Abstractions/EndpointMetadataCollection.cs +++ b/src/Microsoft.AspNetCore.Routing.Abstractions/EndpointMetadataCollection.cs @@ -112,8 +112,7 @@ namespace Microsoft.AspNetCore.Routing var items = new List(); for (var i = 0; i < _items.Length; i++) { - var item = _items[i] as T; - if (item != null) + if (_items[i] is T item) { items.Add(item); } @@ -150,19 +149,18 @@ namespace Microsoft.AspNetCore.Routing // Intentionally not readonly to prevent defensive struct copies private object[] _items; private int _index; - private object _current; internal Enumerator(EndpointMetadataCollection collection) { _items = collection._items; _index = 0; - _current = null; + Current = null; } /// /// Gets the element at the current position of the enumerator /// - public object Current => _current; + public object Current { get; private set; } /// /// Releases all resources used by the . @@ -182,11 +180,11 @@ namespace Microsoft.AspNetCore.Routing { if (_index < _items.Length) { - _current = _items[_index++]; + Current = _items[_index++]; return true; } - _current = null; + Current = null; return false; } @@ -196,7 +194,7 @@ namespace Microsoft.AspNetCore.Routing public void Reset() { _index = 0; - _current = null; + Current = null; } } } diff --git a/src/Microsoft.AspNetCore.Routing.Abstractions/RouteValueDictionary.cs b/src/Microsoft.AspNetCore.Routing.Abstractions/RouteValueDictionary.cs index 182147b9af..2d30f6f25f 100644 --- a/src/Microsoft.AspNetCore.Routing.Abstractions/RouteValueDictionary.cs +++ b/src/Microsoft.AspNetCore.Routing.Abstractions/RouteValueDictionary.cs @@ -222,13 +222,7 @@ namespace Microsoft.AspNetCore.Routing } } - IEnumerable IReadOnlyDictionary.Keys - { - get - { - return Keys; - } - } + IEnumerable IReadOnlyDictionary.Keys => Keys; /// public ICollection Values @@ -248,13 +242,7 @@ namespace Microsoft.AspNetCore.Routing } } - IEnumerable IReadOnlyDictionary.Values - { - get - { - return Values; - } - } + IEnumerable IReadOnlyDictionary.Values => Values; /// void ICollection>.Add(KeyValuePair item) @@ -565,7 +553,7 @@ namespace Microsoft.AspNetCore.Routing internal class PropertyStorage { - private static readonly PropertyCache _propertyCache = new PropertyCache(); + private static readonly ConcurrentDictionary _propertyCache = new ConcurrentDictionary(); public readonly object Value; public readonly PropertyHelper[] Properties; @@ -606,9 +594,5 @@ namespace Microsoft.AspNetCore.Routing } } } - - private class PropertyCache : ConcurrentDictionary - { - } } }