Correct a few model binding typos

- worst cases were incorrect references in doc comments
- also a few doc comments ended with `..` or `/`
- otherwise, address nits and take VS suggestions
This commit is contained in:
Doug Bunting 2016-10-30 18:16:51 -07:00
parent 913cefdea2
commit 58026eacbd
7 changed files with 49 additions and 33 deletions

View File

@ -68,7 +68,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
public abstract string ModelName { get; set; } public abstract string ModelName { get; set; }
/// <summary> /// <summary>
/// Gets or sets the <see cref="ModelStateDictionary"/> used to capture <see cref="ModelState"/> values /// Gets or sets the <see cref="ModelStateDictionary"/> used to capture <see cref="ModelStateEntry"/> values
/// for properties in the object graph of the model when binding. /// for properties in the object graph of the model when binding.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
@ -117,21 +117,33 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
public abstract ModelBindingResult Result { get; set; } public abstract ModelBindingResult Result { get; set; }
/// <summary> /// <summary>
/// Pushes a layer of state onto this context. Model binders will call this as part of recursion when binding properties /// Pushes a layer of state onto this context. Model binders will call this as part of recursion when binding
/// or collection items. /// properties or collection items.
/// </summary> /// </summary>
/// <param name="modelMetadata"><see cref="ModelBinding.ModelMetadata"/> to assign to the <see cref="ModelMetadata"/> property.</param> /// <param name="modelMetadata">
/// <see cref="ModelBinding.ModelMetadata"/> to assign to the <see cref="ModelMetadata"/> property.
/// </param>
/// <param name="fieldName">Name to assign to the <see cref="FieldName"/> property.</param> /// <param name="fieldName">Name to assign to the <see cref="FieldName"/> property.</param>
/// <param name="modelName">Name to assign to the <see cref="ModelName"/> property.</param> /// <param name="modelName">Name to assign to the <see cref="ModelName"/> property.</param>
/// <param name="model">Instance to assign to the <see cref="Model"/> property.</param> /// <param name="model">Instance to assign to the <see cref="Model"/> property.</param>
/// <returns>A <see cref="NestedScope"/> scope object which should be used in a using statement where PushContext is called.</returns> /// <returns>
public abstract NestedScope EnterNestedScope(ModelMetadata modelMetadata, string fieldName, string modelName, object model); /// A <see cref="NestedScope"/> scope object which should be used in a <c>using</c> statement where
/// <see cref="EnterNestedScope(ModelMetadata, string, string, object)"/> is called.
/// </returns>
public abstract NestedScope EnterNestedScope(
ModelMetadata modelMetadata,
string fieldName,
string modelName,
object model);
/// <summary> /// <summary>
/// Pushes a layer of state onto this context. Model binders will call this as part of recursion when binding properties /// Pushes a layer of state onto this context. Model binders will call this as part of recursion when binding
/// or collection items. /// properties or collection items.
/// </summary> /// </summary>
/// <returns>A <see cref="NestedScope"/> scope object which should be used in a using statement where PushContext is called.</returns> /// <returns>
/// A <see cref="NestedScope"/> scope object which should be used in a <c>using</c> statement where
/// <see cref="EnterNestedScope()"/> is called.
/// </returns>
public abstract NestedScope EnterNestedScope(); public abstract NestedScope EnterNestedScope();
/// <summary> /// <summary>
@ -141,7 +153,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
/// <summary> /// <summary>
/// Return value of <see cref="M:EnterNestedScope"/>. Should be disposed /// Return value of <see cref="M:EnterNestedScope"/>. Should be disposed
/// by caller when child binding context state should be popped off of /// by caller when child binding context state should be popped off of
/// the <see cref="ModelBindingContext"/>. /// the <see cref="ModelBindingContext"/>.
/// </summary> /// </summary>
public struct NestedScope : IDisposable public struct NestedScope : IDisposable

View File

@ -50,17 +50,26 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
public abstract bool IsContainerNode { get; } public abstract bool IsContainerNode { get; }
/// <summary> /// <summary>
/// Gets the <see cref="ModelStateEntry"/> for a sub-property with the specified <paramref name="propertyName"/>. /// Gets the <see cref="ModelStateEntry"/> for a sub-property with the specified
/// <paramref name="propertyName"/>.
/// </summary> /// </summary>
/// <param name="propertyName">The property name to lookup.</param> /// <param name="propertyName">The property name to lookup.</param>
/// <returns>The <see cref="ModelStateEntry"/> if a sub-property was found; otherwise <c>null</c>.</returns> /// <returns>
/// <remarks>This method returns any existing entry, even those with <see cref="IsContainerNode"/> with value <c>true</c>..</remarks> /// The <see cref="ModelStateEntry"/> if a sub-property was found; otherwise <see langword="null"/>.
/// </returns>
/// <remarks>
/// This method returns any existing entry, even those with <see cref="IsContainerNode"/> with value
/// <see langword="true"/>.
/// </remarks>
public abstract ModelStateEntry GetModelStateForProperty(string propertyName); public abstract ModelStateEntry GetModelStateForProperty(string propertyName);
/// <summary> /// <summary>
/// Gets the <see cref="ModelStateEntry"/> values for sub-properties. /// Gets the <see cref="ModelStateEntry"/> values for sub-properties.
/// </summary> /// </summary>
/// <remarks>This method returns all existing entries, even those with <see cref="IsContainerNode"/> with value <c>true</c>.</remarks> /// <remarks>
/// This property returns all existing entries, even those with <see cref="IsContainerNode"/> with value
/// <see langword="true"/>.
/// </remarks>
public abstract IReadOnlyList<ModelStateEntry> Children { get; } public abstract IReadOnlyList<ModelStateEntry> Children { get; }
} }
} }

View File

@ -296,7 +296,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
{ {
_stack.Push(_state); _stack.Push(_state);
Result = default(ModelBindingResult); Result = default;
return new NestedScope(this); return new NestedScope(this);
} }
@ -338,6 +338,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
public bool IsTopLevelObject; public bool IsTopLevelObject;
public ModelBindingResult Result; public ModelBindingResult Result;
}; }
} }
} }

View File

@ -143,6 +143,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
if (formatter == null) if (formatter == null)
{ {
_logger?.NoInputFormatterSelected(formatterContext); _logger?.NoInputFormatterSelected(formatterContext);
var message = Resources.FormatUnsupportedContentType(httpContext.Request.ContentType); var message = Resources.FormatUnsupportedContentType(httpContext.Request.ContentType);
var exception = new UnsupportedContentTypeException(message); var exception = new UnsupportedContentTypeException(message);
bindingContext.ModelState.AddModelError(modelBindingKey, exception, bindingContext.ModelMetadata); bindingContext.ModelState.AddModelError(modelBindingKey, exception, bindingContext.ModelMetadata);
@ -152,7 +153,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
try try
{ {
var result = await formatter.ReadAsync(formatterContext); var result = await formatter.ReadAsync(formatterContext);
var model = result.Model;
if (result.HasError) if (result.HasError)
{ {
@ -162,6 +162,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
if (result.IsModelSet) if (result.IsModelSet)
{ {
var model = result.Model;
bindingContext.Result = ModelBindingResult.Success(model); bindingContext.Result = ModelBindingResult.Success(model);
} }
else else

View File

@ -181,6 +181,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
bindingContext.ValueProvider bindingContext.ValueProvider
}; };
// Enter new scope to change ModelMetadata and isolate element binding operations.
using (bindingContext.EnterNestedScope( using (bindingContext.EnterNestedScope(
elementMetadata, elementMetadata,
fieldName: bindingContext.FieldName, fieldName: bindingContext.FieldName,
@ -238,8 +239,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
{ {
var fullChildName = ModelNames.CreateIndexModelName(bindingContext.ModelName, indexName); var fullChildName = ModelNames.CreateIndexModelName(bindingContext.ModelName, indexName);
var didBind = false;
object boundValue = null;
ModelBindingResult? result; ModelBindingResult? result;
using (bindingContext.EnterNestedScope( using (bindingContext.EnterNestedScope(
elementMetadata, elementMetadata,
@ -251,6 +250,8 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
result = bindingContext.Result; result = bindingContext.Result;
} }
var didBind = false;
object boundValue = null;
if (result != null && result.Value.IsModelSet) if (result != null && result.Value.IsModelSet)
{ {
didBind = true; didBind = true;
@ -296,10 +297,11 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
/// </summary> /// </summary>
/// <param name="targetType"><see cref="Type"/> of the model.</param> /// <param name="targetType"><see cref="Type"/> of the model.</param>
/// <param name="collection"> /// <param name="collection">
/// Collection of values retrieved from value providers. Or <c>null</c> if nothing was bound. /// Collection of values retrieved from value providers. <see langword="null"/> if nothing was bound.
/// </param> /// </param>
/// <returns> /// <returns>
/// An <see cref="object"/> assignable to <paramref name="targetType"/>. Or <c>null</c> if nothing was bound. /// An <see cref="object"/> assignable to <paramref name="targetType"/>. <see langword="null"/> if nothing
/// was bound.
/// </returns> /// </returns>
/// <remarks> /// <remarks>
/// Extensibility point that allows the bound collection to be manipulated or transformed before being /// Extensibility point that allows the bound collection to be manipulated or transformed before being
@ -330,7 +332,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
/// </summary> /// </summary>
/// <param name="target"><see cref="object"/> into which values are copied.</param> /// <param name="target"><see cref="object"/> into which values are copied.</param>
/// <param name="sourceCollection"> /// <param name="sourceCollection">
/// Collection of values retrieved from value providers. Or <c>null</c> if nothing was bound. /// Collection of values retrieved from value providers. <see langword="null"/> if nothing was bound.
/// </param> /// </param>
protected virtual void CopyToModel(object target, IEnumerable<TElement> sourceCollection) protected virtual void CopyToModel(object target, IEnumerable<TElement> sourceCollection)
{ {

View File

@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
{ {
/// <summary> /// <summary>
/// An <see cref="IModelBinder"/> which binds models from the request headers when a model /// An <see cref="IModelBinder"/> which binds models from the request headers when a model
/// has the binding source <see cref="BindingSource.Header"/>/ /// has the binding source <see cref="BindingSource.Header"/>.
/// </summary> /// </summary>
public class HeaderModelBinder : IModelBinder public class HeaderModelBinder : IModelBinder
{ {
@ -80,7 +80,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
} }
var collection = ModelBindingHelper.GetCompatibleCollection<string>(bindingContext, values.Length); var collection = ModelBindingHelper.GetCompatibleCollection<string>(bindingContext, values.Length);
for (int i = 0; i < values.Length; i++) for (var i = 0; i < values.Length; i++)
{ {
collection.Add(values[i]); collection.Add(values[i]);
} }
@ -88,4 +88,4 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
return collection; return collection;
} }
} }
} }

View File

@ -871,14 +871,6 @@ namespace Microsoft.AspNetCore.Mvc.Internal
{ nameof(TestController.NullCollectionProperty), new List<string> { "hello", "world" } }, { nameof(TestController.NullCollectionProperty), new List<string> { "hello", "world" } },
{ nameof(TestController.StringProperty), "Hello" }, { nameof(TestController.StringProperty), "Hello" },
}; };
var expectedPropertyValues = new Dictionary<string, object>
{
{ nameof(TestController.ArrayProperty), new string[] { "goodbye" } },
{ nameof(TestController.CollectionProperty), new List<string> { "hello", "world" } },
{ nameof(TestController.NonCollectionProperty), new Person { Name = "Ginger" } },
{ nameof(TestController.NullCollectionProperty), null },
{ nameof(TestController.StringProperty), "Hello" },
};
var actionDescriptor = GetActionDescriptor(); var actionDescriptor = GetActionDescriptor();
foreach (var keyValuePair in boundPropertyTypes) foreach (var keyValuePair in boundPropertyTypes)