Quick fix: Address a couple of nits in / around `ViewDataDictionary`

- remove duplicate `null` checks in `ViewDataDictionary` constructors
- correct a couple of code comments
- use a `public` constructor for `ViewDataDictionary` in `ViewExecutor`
This commit is contained in:
Doug Bunting 2016-04-01 14:11:00 -07:00
parent 341430eae5
commit 384fd1f218
4 changed files with 6 additions and 59 deletions

View File

@ -4,8 +4,8 @@
using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Reflection;
using System.Linq.Expressions;
using System.Reflection;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.Razor.Internal;
using Microsoft.AspNetCore.Mvc.Rendering;
@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor
private ViewDataDictionary CreateViewDataDictionary(ViewContext context, PageActivationInfo activationInfo)
{
// Create a ViewDataDictionary<TModel> if the ViewContext.ViewData is not set or the type of
// ViewContext.ViewData is an incompatibile type.
// ViewContext.ViewData is an incompatible type.
if (context.ViewData == null)
{
// Create ViewDataDictionary<TModel>(IModelMetadataProvider, ModelStateDictionary).

View File

@ -33,14 +33,6 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
ModelStateDictionary modelState)
: this(metadataProvider, modelState, declaredModelType: typeof(object))
{
if (metadataProvider == null)
{
throw new ArgumentNullException(nameof(metadataProvider));
}
if (modelState == null)
{
throw new ArgumentNullException(nameof(modelState));
}
}
/// <summary>
@ -56,10 +48,6 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
public ViewDataDictionary(ViewDataDictionary source)
: this(source, source.Model, source._declaredModelType)
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
}
/// <summary>
@ -77,10 +65,6 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
public ViewDataDictionary(ViewDataDictionary source, object model)
: this(source, model, declaredModelType: typeof(object))
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
}
/// <summary>
@ -94,10 +78,6 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
internal ViewDataDictionary(IModelMetadataProvider metadataProvider)
: this(metadataProvider, new ModelStateDictionary())
{
if (metadataProvider == null)
{
throw new ArgumentNullException(nameof(metadataProvider));
}
}
/// <summary>
@ -119,14 +99,6 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
Type declaredModelType)
: this(metadataProvider, new ModelStateDictionary(), declaredModelType)
{
if (metadataProvider == null)
{
throw new ArgumentNullException(nameof(metadataProvider));
}
if (declaredModelType == null)
{
throw new ArgumentNullException(nameof(declaredModelType));
}
}
/// <summary>
@ -198,10 +170,6 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
protected ViewDataDictionary(ViewDataDictionary source, Type declaredModelType)
: this(source, model: source.Model, declaredModelType: declaredModelType)
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
}
/// <summary>

View File

@ -1,7 +1,6 @@
// 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 Microsoft.AspNetCore.Mvc.ModelBinding;
namespace Microsoft.AspNetCore.Mvc.ViewFeatures
@ -15,20 +14,12 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
/// For use when creating a <see cref="ViewDataDictionary{TModel}"/> for a new top-level scope.
/// </remarks>
/// <inheritdoc />
// References may not show up due to ActivatorUtilities use in RazorPageActivator.
// References may not show up due to Type.GetConstructor() use in RazorPageActivator.
public ViewDataDictionary(
IModelMetadataProvider metadataProvider,
ModelStateDictionary modelState)
: base(metadataProvider, modelState, declaredModelType: typeof(TModel))
{
if (metadataProvider == null)
{
throw new ArgumentNullException(nameof(metadataProvider));
}
if (modelState == null)
{
throw new ArgumentNullException(nameof(modelState));
}
}
/// <summary>
@ -48,14 +39,10 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
/// </para>
/// </remarks>
/// <inheritdoc />
// References may not show up due to ActivatorUtilities use in RazorPageActivator.
// References may not show up due to Type.GetConstructor() use in RazorPageActivator.
public ViewDataDictionary(ViewDataDictionary source)
: base(source, declaredModelType: typeof(TModel))
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
}
/// <summary>
@ -80,10 +67,6 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
public ViewDataDictionary(ViewDataDictionary source, object model)
: base(source, model, declaredModelType: typeof(TModel))
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
}
/// <summary>
@ -94,10 +77,6 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
internal ViewDataDictionary(IModelMetadataProvider metadataProvider)
: base(metadataProvider, declaredModelType: typeof(TModel))
{
if (metadataProvider == null)
{
throw new ArgumentNullException(nameof(metadataProvider));
}
}
public new TModel Model

View File

@ -130,11 +130,11 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
throw new ArgumentNullException(nameof(view));
}
var services = actionContext.HttpContext.RequestServices;
if (viewData == null)
{
var services = actionContext.HttpContext.RequestServices;
var metadataProvider = services.GetRequiredService<IModelMetadataProvider>();
viewData = new ViewDataDictionary(metadataProvider);
viewData = new ViewDataDictionary(metadataProvider, actionContext.ModelState);
}
if (tempData == null)