Make fewer public API changes
This commit is contained in:
parent
4f1b7ccca6
commit
174c5eaa6c
|
|
@ -81,7 +81,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata
|
||||||
/// <param name="parameter">The <see cref="ParameterInfo" />.</param>
|
/// <param name="parameter">The <see cref="ParameterInfo" />.</param>
|
||||||
/// <param name="modelType">The model type.</param>
|
/// <param name="modelType">The model type.</param>
|
||||||
/// <returns>A <see cref="ModelMetadataIdentity"/>.</returns>
|
/// <returns>A <see cref="ModelMetadataIdentity"/>.</returns>
|
||||||
public static ModelMetadataIdentity ForParameter(ParameterInfo parameter, Type modelType)
|
private static ModelMetadataIdentity ForParameter(ParameterInfo parameter, Type modelType)
|
||||||
{
|
{
|
||||||
if (parameter == null)
|
if (parameter == null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -32,27 +32,5 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
|
||||||
/// <param name="parameter">The <see cref="ParameterInfo"/>.</param>
|
/// <param name="parameter">The <see cref="ParameterInfo"/>.</param>
|
||||||
/// <returns>A <see cref="ModelMetadata"/> instance describing the <paramref name="parameter"/>.</returns>
|
/// <returns>A <see cref="ModelMetadata"/> instance describing the <paramref name="parameter"/>.</returns>
|
||||||
public abstract ModelMetadata GetMetadataForParameter(ParameterInfo parameter);
|
public abstract ModelMetadata GetMetadataForParameter(ParameterInfo parameter);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Supplies metadata describing a parameter.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="parameter">The <see cref="ParameterInfo"/></param>
|
|
||||||
/// <param name="modelType">The actual model type.</param>
|
|
||||||
/// <returns>A <see cref="ModelMetadata"/> instance describing the <paramref name="parameter"/>.</returns>
|
|
||||||
public virtual ModelMetadata GetMetadataForParameter(ParameterInfo parameter, Type modelType)
|
|
||||||
{
|
|
||||||
throw new NotSupportedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Supplies metadata describing a property.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="propertyInfo">The <see cref="PropertyInfo"/>.</param>
|
|
||||||
/// <param name="modelType">The actual model type.</param>
|
|
||||||
/// <returns>A <see cref="ModelMetadata"/> instance describing the <paramref name="propertyInfo"/>.</returns>
|
|
||||||
public virtual ModelMetadata GetMetadataForProperty(PropertyInfo propertyInfo, Type modelType)
|
|
||||||
{
|
|
||||||
throw new NotSupportedException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Controllers
|
namespace Microsoft.AspNetCore.Mvc.Controllers
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Controllers
|
namespace Microsoft.AspNetCore.Mvc.Controllers
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
namespace Microsoft.AspNetCore.Mvc.Internal
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A <see cref="ParameterDescriptor"/> for action parameters.
|
/// A <see cref="ParameterDescriptor"/> for action parameters.
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
namespace Microsoft.AspNetCore.Mvc.Internal
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A <see cref="ParameterDescriptor"/> for bound properties.
|
/// A <see cref="ParameterDescriptor"/> for bound properties.
|
||||||
|
|
@ -14,12 +14,27 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A default implementation of <see cref="IModelMetadataProvider"/> based on reflection.
|
/// A default implementation of <see cref="IModelMetadataProvider"/> based on reflection.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DefaultModelMetadataProvider : ModelMetadataProvider
|
public class DefaultModelMetadataProvider : ModelMetadataProvider, IModelMetadataProvider2
|
||||||
{
|
{
|
||||||
|
private static readonly Func<ParameterInfo, Type, ModelMetadataIdentity> _modelMetadataIdentityForParameter;
|
||||||
|
|
||||||
private readonly TypeCache _typeCache = new TypeCache();
|
private readonly TypeCache _typeCache = new TypeCache();
|
||||||
private readonly Func<ModelMetadataIdentity, ModelMetadataCacheEntry> _cacheEntryFactory;
|
private readonly Func<ModelMetadataIdentity, ModelMetadataCacheEntry> _cacheEntryFactory;
|
||||||
private readonly ModelMetadataCacheEntry _metadataCacheEntryForObjectType;
|
private readonly ModelMetadataCacheEntry _metadataCacheEntryForObjectType;
|
||||||
|
|
||||||
|
static DefaultModelMetadataProvider()
|
||||||
|
{
|
||||||
|
var forParameterMethod = typeof(ModelMetadataIdentity).GetMethod(
|
||||||
|
nameof(ModelMetadataIdentity.ForParameter),
|
||||||
|
BindingFlags.Static | BindingFlags.NonPublic,
|
||||||
|
binder: null,
|
||||||
|
types: new[] { typeof(ParameterInfo), typeof(Type) },
|
||||||
|
modifiers: null);
|
||||||
|
|
||||||
|
_modelMetadataIdentityForParameter = (Func<ParameterInfo, Type, ModelMetadataIdentity>)
|
||||||
|
forParameterMethod.CreateDelegate(typeof(Func<ParameterInfo, Type, ModelMetadataIdentity>));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new <see cref="DefaultModelMetadataProvider"/>.
|
/// Creates a new <see cref="DefaultModelMetadataProvider"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -103,7 +118,10 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata
|
||||||
=> GetMetadataForParameter(parameter, parameter?.ParameterType);
|
=> GetMetadataForParameter(parameter, parameter?.ParameterType);
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override ModelMetadata GetMetadataForParameter(ParameterInfo parameter, Type modelType)
|
ModelMetadata IModelMetadataProvider2.GetMetadataForParameter(ParameterInfo parameter, Type modelType)
|
||||||
|
=> GetMetadataForParameter(parameter, modelType);
|
||||||
|
|
||||||
|
internal ModelMetadata GetMetadataForParameter(ParameterInfo parameter, Type modelType)
|
||||||
{
|
{
|
||||||
if (parameter == null)
|
if (parameter == null)
|
||||||
{
|
{
|
||||||
|
|
@ -133,8 +151,12 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata
|
||||||
return cacheEntry.Metadata;
|
return cacheEntry.Metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override ModelMetadata GetMetadataForProperty(PropertyInfo propertyInfo, Type modelType)
|
ModelMetadata IModelMetadataProvider2.GetMetadataForProperty(PropertyInfo parameter, Type modelType)
|
||||||
|
=> GetMetadataForProperty(parameter, modelType);
|
||||||
|
|
||||||
|
internal ModelMetadata GetMetadataForProperty(PropertyInfo propertyInfo, Type modelType)
|
||||||
{
|
{
|
||||||
if (propertyInfo == null)
|
if (propertyInfo == null)
|
||||||
{
|
{
|
||||||
|
|
@ -183,7 +205,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata
|
||||||
private ModelMetadataCacheEntry GetCacheEntry(ParameterInfo parameter, Type modelType)
|
private ModelMetadataCacheEntry GetCacheEntry(ParameterInfo parameter, Type modelType)
|
||||||
{
|
{
|
||||||
return _typeCache.GetOrAdd(
|
return _typeCache.GetOrAdd(
|
||||||
ModelMetadataIdentity.ForParameter(parameter, modelType),
|
_modelMetadataIdentityForParameter(parameter, modelType),
|
||||||
_cacheEntryFactory);
|
_cacheEntryFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNetCore.Mvc.ModelBinding
|
||||||
|
{
|
||||||
|
internal interface IModelMetadataProvider2
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Supplies metadata describing a parameter.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="parameter">The <see cref="ParameterInfo"/></param>
|
||||||
|
/// <param name="modelType">The actual model type.</param>
|
||||||
|
/// <returns>A <see cref="ModelMetadata"/> instance describing the <paramref name="parameter"/>.</returns>
|
||||||
|
ModelMetadata GetMetadataForParameter(ParameterInfo parameter, Type modelType);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Supplies metadata describing a property.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="propertyInfo">The <see cref="PropertyInfo"/>.</param>
|
||||||
|
/// <param name="modelType">The actual model type.</param>
|
||||||
|
/// <returns>A <see cref="ModelMetadata"/> instance describing the <paramref name="propertyInfo"/>.</returns>
|
||||||
|
ModelMetadata GetMetadataForProperty(PropertyInfo propertyInfo, Type modelType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -149,7 +149,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// A <see cref="ModelAttributes"/> instance with the attributes of the property and its <see cref="Type"/>.
|
/// A <see cref="ModelAttributes"/> instance with the attributes of the property and its <see cref="Type"/>.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public static ModelAttributes GetAttributesForProperty(Type containerType, PropertyInfo property, Type modelType)
|
internal static ModelAttributes GetAttributesForProperty(Type containerType, PropertyInfo property, Type modelType)
|
||||||
{
|
{
|
||||||
if (containerType == null)
|
if (containerType == null)
|
||||||
{
|
{
|
||||||
|
|
@ -231,7 +231,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// A <see cref="ModelAttributes"/> instance with the attributes of the parameter and its <see cref="Type"/>.
|
/// A <see cref="ModelAttributes"/> instance with the attributes of the parameter and its <see cref="Type"/>.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public static ModelAttributes GetAttributesForParameter(ParameterInfo parameterInfo, Type modelType)
|
internal static ModelAttributes GetAttributesForParameter(ParameterInfo parameterInfo, Type modelType)
|
||||||
{
|
{
|
||||||
if (parameterInfo == null)
|
if (parameterInfo == null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -344,7 +344,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
|
||||||
|
|
||||||
if (!modelBindingResult.IsModelSet ||
|
if (!modelBindingResult.IsModelSet ||
|
||||||
modelBindingResult.Model == null ||
|
modelBindingResult.Model == null ||
|
||||||
!(_modelMetadataProvider is ModelMetadataProvider modelMetadataProvider))
|
!(_modelMetadataProvider is IModelMetadataProvider2 modelMetadataProvider))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
|
namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
|
namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue