From 296ec7736ef8155268aeebdc0889e77442906ff6 Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Sun, 14 Jun 2015 18:02:10 -0700 Subject: [PATCH] Go one less step when resolving `[ModelMetadataType]` - #2610 - make MVC 6's attribute consistent with data annotation's `[MetadataType]`, used in MVC 5 --- .../ModelBinding/Metadata/ModelAttributes.cs | 3 --- .../ModelBinding/Metadata/ModelAttributesTest.cs | 10 ++++------ 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/ModelAttributes.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/ModelAttributes.cs index 019d37a6af..a6a7c3d5b1 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/ModelAttributes.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/ModelAttributes.cs @@ -77,9 +77,6 @@ namespace Microsoft.AspNet.Mvc.ModelBinding if (metadataProperty != null) { propertyAttributes = propertyAttributes.Concat(metadataProperty.GetCustomAttributes()); - - var propertyMetadataType = metadataProperty.PropertyType; - typeAttributes = typeAttributes.Concat(propertyMetadataType.GetTypeInfo().GetCustomAttributes()); } } diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/Metadata/ModelAttributesTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/Metadata/ModelAttributesTest.cs index 5aae1584a0..8fc67160b2 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/Metadata/ModelAttributesTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/Metadata/ModelAttributesTest.cs @@ -165,19 +165,17 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var attributes = ModelAttributes.GetAttributesForProperty(typeof(MergedAttributes), property); // Assert - Assert.Equal(4, attributes.Attributes.Count); + Assert.Equal(3, attributes.Attributes.Count); Assert.IsType(attributes.Attributes[0]); Assert.IsType(attributes.Attributes[1]); Assert.IsType(attributes.Attributes[2]); - Assert.IsType(attributes.Attributes[3]); Assert.Equal(2, attributes.PropertyAttributes.Count); Assert.IsType(attributes.PropertyAttributes[0]); Assert.IsType(attributes.PropertyAttributes[1]); - Assert.Equal(2, attributes.TypeAttributes.Count); - Assert.IsType(attributes.TypeAttributes[0]); - Assert.IsType(attributes.TypeAttributes[1]); + var attribute = Assert.Single(attributes.TypeAttributes); + Assert.IsType(attribute); } [ClassValidator] @@ -207,7 +205,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding [Range(10,100)] public override int VirtualProperty { get; set; } - + } [ModelMetadataType(typeof(BaseModel))]