Go one less step when resolving `[ModelMetadataType]`
- #2610 - make MVC 6's attribute consistent with data annotation's `[MetadataType]`, used in MVC 5
This commit is contained in:
parent
faaba481e8
commit
296ec7736e
|
|
@ -77,9 +77,6 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||||
if (metadataProperty != null)
|
if (metadataProperty != null)
|
||||||
{
|
{
|
||||||
propertyAttributes = propertyAttributes.Concat(metadataProperty.GetCustomAttributes());
|
propertyAttributes = propertyAttributes.Concat(metadataProperty.GetCustomAttributes());
|
||||||
|
|
||||||
var propertyMetadataType = metadataProperty.PropertyType;
|
|
||||||
typeAttributes = typeAttributes.Concat(propertyMetadataType.GetTypeInfo().GetCustomAttributes());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -165,19 +165,17 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||||
var attributes = ModelAttributes.GetAttributesForProperty(typeof(MergedAttributes), property);
|
var attributes = ModelAttributes.GetAttributesForProperty(typeof(MergedAttributes), property);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(4, attributes.Attributes.Count);
|
Assert.Equal(3, attributes.Attributes.Count);
|
||||||
Assert.IsType<RequiredAttribute>(attributes.Attributes[0]);
|
Assert.IsType<RequiredAttribute>(attributes.Attributes[0]);
|
||||||
Assert.IsType<RangeAttribute>(attributes.Attributes[1]);
|
Assert.IsType<RangeAttribute>(attributes.Attributes[1]);
|
||||||
Assert.IsType<ClassValidator>(attributes.Attributes[2]);
|
Assert.IsType<ClassValidator>(attributes.Attributes[2]);
|
||||||
Assert.IsType<BindAttribute>(attributes.Attributes[3]);
|
|
||||||
|
|
||||||
Assert.Equal(2, attributes.PropertyAttributes.Count);
|
Assert.Equal(2, attributes.PropertyAttributes.Count);
|
||||||
Assert.IsType<RequiredAttribute>(attributes.PropertyAttributes[0]);
|
Assert.IsType<RequiredAttribute>(attributes.PropertyAttributes[0]);
|
||||||
Assert.IsType<RangeAttribute>(attributes.PropertyAttributes[1]);
|
Assert.IsType<RangeAttribute>(attributes.PropertyAttributes[1]);
|
||||||
|
|
||||||
Assert.Equal(2, attributes.TypeAttributes.Count);
|
var attribute = Assert.Single(attributes.TypeAttributes);
|
||||||
Assert.IsType<ClassValidator>(attributes.TypeAttributes[0]);
|
Assert.IsType<ClassValidator>(attribute);
|
||||||
Assert.IsType<BindAttribute>(attributes.TypeAttributes[1]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[ClassValidator]
|
[ClassValidator]
|
||||||
|
|
@ -207,7 +205,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||||
|
|
||||||
[Range(10,100)]
|
[Range(10,100)]
|
||||||
public override int VirtualProperty { get; set; }
|
public override int VirtualProperty { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[ModelMetadataType(typeof(BaseModel))]
|
[ModelMetadataType(typeof(BaseModel))]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue