diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelPropertyCollection.cs b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelPropertyCollection.cs
index 88ac5170c8..434ff52af8 100644
--- a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelPropertyCollection.cs
+++ b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelPropertyCollection.cs
@@ -2,50 +2,35 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
-using System.Collections;
using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
namespace Microsoft.AspNet.Mvc.ModelBinding
{
///
- /// A read-only list of objects which represent model properties.
+ /// A read-only collection of objects which represent model properties.
///
- public class ModelPropertyCollection : IReadOnlyList
+ public class ModelPropertyCollection : ReadOnlyCollection
{
- private readonly List _properties;
-
///
/// Creates a new .
///
/// The properties.
public ModelPropertyCollection(IEnumerable properties)
+ : base(properties.ToList())
{
- if (properties == null)
- {
- throw new ArgumentNullException(nameof(properties));
- }
-
- _properties = new List(properties);
- }
-
- ///
- public ModelMetadata this[int index]
- {
- get
- {
- return _properties[index];
- }
}
///
/// Gets a instance for the property corresponding to .
///
///
- /// The property name. Property names are compared using
+ /// The property name. Property names are compared using .
///
///
- /// The instance for the property specified by , or null
- /// if no match can be found.
+ /// The instance for the property specified by , or
+ /// null if no match can be found.
///
public ModelMetadata this[string propertyName]
{
@@ -56,8 +41,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
throw new ArgumentNullException(nameof(propertyName));
}
- foreach (var property in _properties)
+ for (var i = 0; i < Items.Count; i++)
{
+ var property = Items[i];
if (string.Equals(property.PropertyName, propertyName, StringComparison.Ordinal))
{
return property;
@@ -67,26 +53,5 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
return null;
}
}
-
- ///
- public int Count
- {
- get
- {
- return _properties.Count;
- }
- }
-
- ///
- public IEnumerator GetEnumerator()
- {
- return _properties.GetEnumerator();
- }
-
- ///
- IEnumerator IEnumerable.GetEnumerator()
- {
- return GetEnumerator();
- }
}
}
\ No newline at end of file