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:
parent
341430eae5
commit
384fd1f218
|
|
@ -4,8 +4,8 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
|
using System.Reflection;
|
||||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||||
using Microsoft.AspNetCore.Mvc.Razor.Internal;
|
using Microsoft.AspNetCore.Mvc.Razor.Internal;
|
||||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||||
|
|
@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
||||||
private ViewDataDictionary CreateViewDataDictionary(ViewContext context, PageActivationInfo activationInfo)
|
private ViewDataDictionary CreateViewDataDictionary(ViewContext context, PageActivationInfo activationInfo)
|
||||||
{
|
{
|
||||||
// Create a ViewDataDictionary<TModel> if the ViewContext.ViewData is not set or the type of
|
// 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)
|
if (context.ViewData == null)
|
||||||
{
|
{
|
||||||
// Create ViewDataDictionary<TModel>(IModelMetadataProvider, ModelStateDictionary).
|
// Create ViewDataDictionary<TModel>(IModelMetadataProvider, ModelStateDictionary).
|
||||||
|
|
|
||||||
|
|
@ -33,14 +33,6 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
||||||
ModelStateDictionary modelState)
|
ModelStateDictionary modelState)
|
||||||
: this(metadataProvider, modelState, declaredModelType: typeof(object))
|
: this(metadataProvider, modelState, declaredModelType: typeof(object))
|
||||||
{
|
{
|
||||||
if (metadataProvider == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(metadataProvider));
|
|
||||||
}
|
|
||||||
if (modelState == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(modelState));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -56,10 +48,6 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
||||||
public ViewDataDictionary(ViewDataDictionary source)
|
public ViewDataDictionary(ViewDataDictionary source)
|
||||||
: this(source, source.Model, source._declaredModelType)
|
: this(source, source.Model, source._declaredModelType)
|
||||||
{
|
{
|
||||||
if (source == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(source));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -77,10 +65,6 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
||||||
public ViewDataDictionary(ViewDataDictionary source, object model)
|
public ViewDataDictionary(ViewDataDictionary source, object model)
|
||||||
: this(source, model, declaredModelType: typeof(object))
|
: this(source, model, declaredModelType: typeof(object))
|
||||||
{
|
{
|
||||||
if (source == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(source));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -94,10 +78,6 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
||||||
internal ViewDataDictionary(IModelMetadataProvider metadataProvider)
|
internal ViewDataDictionary(IModelMetadataProvider metadataProvider)
|
||||||
: this(metadataProvider, new ModelStateDictionary())
|
: this(metadataProvider, new ModelStateDictionary())
|
||||||
{
|
{
|
||||||
if (metadataProvider == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(metadataProvider));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -119,14 +99,6 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
||||||
Type declaredModelType)
|
Type declaredModelType)
|
||||||
: this(metadataProvider, new ModelStateDictionary(), declaredModelType)
|
: this(metadataProvider, new ModelStateDictionary(), declaredModelType)
|
||||||
{
|
{
|
||||||
if (metadataProvider == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(metadataProvider));
|
|
||||||
}
|
|
||||||
if (declaredModelType == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(declaredModelType));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -198,10 +170,6 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
||||||
protected ViewDataDictionary(ViewDataDictionary source, Type declaredModelType)
|
protected ViewDataDictionary(ViewDataDictionary source, Type declaredModelType)
|
||||||
: this(source, model: source.Model, declaredModelType: declaredModelType)
|
: this(source, model: source.Model, declaredModelType: declaredModelType)
|
||||||
{
|
{
|
||||||
if (source == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(source));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// 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.
|
// 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;
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
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.
|
/// For use when creating a <see cref="ViewDataDictionary{TModel}"/> for a new top-level scope.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <inheritdoc />
|
/// <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(
|
public ViewDataDictionary(
|
||||||
IModelMetadataProvider metadataProvider,
|
IModelMetadataProvider metadataProvider,
|
||||||
ModelStateDictionary modelState)
|
ModelStateDictionary modelState)
|
||||||
: base(metadataProvider, modelState, declaredModelType: typeof(TModel))
|
: base(metadataProvider, modelState, declaredModelType: typeof(TModel))
|
||||||
{
|
{
|
||||||
if (metadataProvider == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(metadataProvider));
|
|
||||||
}
|
|
||||||
if (modelState == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(modelState));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -48,14 +39,10 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
||||||
/// </para>
|
/// </para>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <inheritdoc />
|
/// <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)
|
public ViewDataDictionary(ViewDataDictionary source)
|
||||||
: base(source, declaredModelType: typeof(TModel))
|
: base(source, declaredModelType: typeof(TModel))
|
||||||
{
|
{
|
||||||
if (source == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(source));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -80,10 +67,6 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
||||||
public ViewDataDictionary(ViewDataDictionary source, object model)
|
public ViewDataDictionary(ViewDataDictionary source, object model)
|
||||||
: base(source, model, declaredModelType: typeof(TModel))
|
: base(source, model, declaredModelType: typeof(TModel))
|
||||||
{
|
{
|
||||||
if (source == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(source));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -94,10 +77,6 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
||||||
internal ViewDataDictionary(IModelMetadataProvider metadataProvider)
|
internal ViewDataDictionary(IModelMetadataProvider metadataProvider)
|
||||||
: base(metadataProvider, declaredModelType: typeof(TModel))
|
: base(metadataProvider, declaredModelType: typeof(TModel))
|
||||||
{
|
{
|
||||||
if (metadataProvider == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(metadataProvider));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public new TModel Model
|
public new TModel Model
|
||||||
|
|
|
||||||
|
|
@ -130,11 +130,11 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
||||||
throw new ArgumentNullException(nameof(view));
|
throw new ArgumentNullException(nameof(view));
|
||||||
}
|
}
|
||||||
|
|
||||||
var services = actionContext.HttpContext.RequestServices;
|
|
||||||
if (viewData == null)
|
if (viewData == null)
|
||||||
{
|
{
|
||||||
|
var services = actionContext.HttpContext.RequestServices;
|
||||||
var metadataProvider = services.GetRequiredService<IModelMetadataProvider>();
|
var metadataProvider = services.GetRequiredService<IModelMetadataProvider>();
|
||||||
viewData = new ViewDataDictionary(metadataProvider);
|
viewData = new ViewDataDictionary(metadataProvider, actionContext.ModelState);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tempData == null)
|
if (tempData == null)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue