From c0179f74cc3aad7950276f249dffdb77adc93bdd Mon Sep 17 00:00:00 2001 From: dougbu Date: Tue, 12 Aug 2014 21:07:43 -0700 Subject: [PATCH] Do not repeatedly evaluate `ModelMetadata.Properties` enumeration - supports useful property updates of `ModelMetadata` instances in the collection - provide a controllable ordering using the `Order` value - part of #964 --- .../Metadata/ModelMetadata.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/ModelMetadata.cs b/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/ModelMetadata.cs index 5e07928cbe..32ae5408d5 100644 --- a/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/ModelMetadata.cs +++ b/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/ModelMetadata.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Globalization; using System.Linq; using Microsoft.AspNet.Mvc.ModelBinding.Internal; @@ -139,8 +140,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding { if (_properties == null) { - _properties = Provider.GetMetadataForProperties(Model, RealModelType); + var properties = Provider.GetMetadataForProperties(Model, RealModelType); + _properties = properties.OrderBy(m => m.Order).ToList(); } + return _properties; } }