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; }
/// <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.
/// </summary>
/// <remarks>
@ -117,21 +117,33 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
public abstract ModelBindingResult Result { get; set; }
/// <summary>
/// Pushes a layer of state onto this context. Model binders will call this as part of recursion when binding properties
/// or collection items.
/// Pushes a layer of state onto this context. Model binders will call this as part of recursion when binding
/// properties or collection items.
/// </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="modelName">Name to assign to the <see cref="ModelName"/> 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>
public abstract NestedScope EnterNestedScope(ModelMetadata modelMetadata, string fieldName, string modelName, object model);
/// <returns>
/// 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>
/// Pushes a layer of state onto this context. Model binders will call this as part of recursion when binding properties
/// or collection items.
/// Pushes a layer of state onto this context. Model binders will call this as part of recursion when binding
/// properties or collection items.
/// </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();
/// <summary>
@ -141,7 +153,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
/// <summary>
/// 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"/>.
/// </summary>
public struct NestedScope : IDisposable

View File

@ -50,17 +50,26 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
public abstract bool IsContainerNode { get; }
/// <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>
/// <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>
/// <remarks>This method returns any existing entry, even those with <see cref="IsContainerNode"/> with value <c>true</c>..</remarks>
/// <returns>
/// 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);
/// <summary>
/// Gets the <see cref="ModelStateEntry"/> values for sub-properties.
/// </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; }
}
}

View File

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

View File

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

View File

@ -181,6 +181,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
bindingContext.ValueProvider
};
// Enter new scope to change ModelMetadata and isolate element binding operations.
using (bindingContext.EnterNestedScope(
elementMetadata,
fieldName: bindingContext.FieldName,
@ -238,8 +239,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
{
var fullChildName = ModelNames.CreateIndexModelName(bindingContext.ModelName, indexName);
var didBind = false;
object boundValue = null;
ModelBindingResult? result;
using (bindingContext.EnterNestedScope(
elementMetadata,
@ -251,6 +250,8 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
result = bindingContext.Result;
}
var didBind = false;
object boundValue = null;
if (result != null && result.Value.IsModelSet)
{
didBind = true;
@ -296,10 +297,11 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
/// </summary>
/// <param name="targetType"><see cref="Type"/> of the model.</param>
/// <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>
/// <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>
/// <remarks>
/// 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>
/// <param name="target"><see cref="object"/> into which values are copied.</param>
/// <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>
protected virtual void CopyToModel(object target, IEnumerable<TElement> sourceCollection)
{

View File

@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
{
/// <summary>
/// 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>
public class HeaderModelBinder : IModelBinder
{
@ -80,7 +80,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
}
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]);
}
@ -88,4 +88,4 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
return collection;
}
}
}
}

View File

@ -871,14 +871,6 @@ namespace Microsoft.AspNetCore.Mvc.Internal
{ nameof(TestController.NullCollectionProperty), new List<string> { "hello", "world" } },
{ 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();
foreach (var keyValuePair in boundPropertyTypes)