Minor RVD and EndpointMetadataCollection refactors (#708)

This commit is contained in:
James Newton-King 2018-08-22 10:30:25 +12:00 committed by GitHub
parent 967afc3b0f
commit 4f33362ab5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 27 deletions

View File

@ -112,8 +112,7 @@ namespace Microsoft.AspNetCore.Routing
var items = new List<T>();
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;
}
/// <summary>
/// Gets the element at the current position of the enumerator
/// </summary>
public object Current => _current;
public object Current { get; private set; }
/// <summary>
/// Releases all resources used by the <see cref="Enumerator"/>.
@ -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;
}
}
}

View File

@ -222,13 +222,7 @@ namespace Microsoft.AspNetCore.Routing
}
}
IEnumerable<string> IReadOnlyDictionary<string, object>.Keys
{
get
{
return Keys;
}
}
IEnumerable<string> IReadOnlyDictionary<string, object>.Keys => Keys;
/// <inheritdoc />
public ICollection<object> Values
@ -248,13 +242,7 @@ namespace Microsoft.AspNetCore.Routing
}
}
IEnumerable<object> IReadOnlyDictionary<string, object>.Values
{
get
{
return Values;
}
}
IEnumerable<object> IReadOnlyDictionary<string, object>.Values => Values;
/// <inheritdoc />
void ICollection<KeyValuePair<string, object>>.Add(KeyValuePair<string, object> item)
@ -565,7 +553,7 @@ namespace Microsoft.AspNetCore.Routing
internal class PropertyStorage
{
private static readonly PropertyCache _propertyCache = new PropertyCache();
private static readonly ConcurrentDictionary<Type, PropertyHelper[]> _propertyCache = new ConcurrentDictionary<Type, PropertyHelper[]>();
public readonly object Value;
public readonly PropertyHelper[] Properties;
@ -606,9 +594,5 @@ namespace Microsoft.AspNetCore.Routing
}
}
}
private class PropertyCache : ConcurrentDictionary<Type, PropertyHelper[]>
{
}
}
}