Add nullability to web.common

This commit is contained in:
Nikolaj Geisle
2022-03-29 13:44:21 +02:00
parent 86ae730b1e
commit b52c4e50cf
151 changed files with 731 additions and 675 deletions

View File

@@ -17,7 +17,7 @@ namespace Umbraco.Cms.Web.Common.Controllers
/// </summary>
protected UmbracoRouteValues GetUmbracoRouteValues(ResultExecutingContext context)
{
UmbracoRouteValues routeVals = context.HttpContext.Features.Get<UmbracoRouteValues>();
UmbracoRouteValues? routeVals = context.HttpContext.Features.Get<UmbracoRouteValues>();
if (routeVals == null)
{
throw new InvalidOperationException($"No {nameof(UmbracoRouteValues)} feature was found in the HttpContext");

View File

@@ -93,8 +93,8 @@ namespace Umbraco.Cms.Web.Common.Controllers
// set the redirect result and do not call next to short circuit
context.Result = pcr.IsRedirectPermanent()
? RedirectPermanent(pcr.RedirectUrl)
: Redirect(pcr.RedirectUrl);
? RedirectPermanent(pcr.RedirectUrl!)
: Redirect(pcr.RedirectUrl!);
break;
case UmbracoRouteResult.NotFound:
// set the redirect result and do not call next to short circuit
@@ -107,10 +107,10 @@ namespace Umbraco.Cms.Web.Common.Controllers
// If there it is means that we are proxying/executing this controller
// from another controller and we need to merge it's ViewData with this one
// since this one will be empty.
ProxyViewDataFeature saveViewData = HttpContext.Features.Get<ProxyViewDataFeature>();
ProxyViewDataFeature? saveViewData = HttpContext.Features.Get<ProxyViewDataFeature>();
if (saveViewData != null)
{
foreach (KeyValuePair<string, object> kv in saveViewData.ViewData)
foreach (KeyValuePair<string, object?> kv in saveViewData.ViewData)
{
ViewData[kv.Key] = kv.Value;
}

View File

@@ -13,7 +13,7 @@ namespace Umbraco.Cms.Web.Common.Controllers
/// </summary>
public abstract class UmbracoPageController : UmbracoController
{
private UmbracoRouteValues _umbracoRouteValues;
private UmbracoRouteValues? _umbracoRouteValues;
private readonly ICompositeViewEngine _compositeViewEngine;
private readonly ILogger<UmbracoPageController> _logger;
@@ -52,7 +52,7 @@ namespace Umbraco.Cms.Web.Common.Controllers
/// <summary>
/// Gets the current content item.
/// </summary>
protected virtual IPublishedContent CurrentPage
protected virtual IPublishedContent? CurrentPage
{
get
{
@@ -88,11 +88,11 @@ namespace Umbraco.Cms.Web.Common.Controllers
/// Ensures that a physical view file exists on disk.
/// </summary>
/// <param name="template">The view name.</param>
protected bool EnsurePhsyicalViewExists(string template)
protected bool EnsurePhsyicalViewExists(string? template)
{
if (string.IsNullOrWhiteSpace(template))
{
string docTypeAlias = UmbracoRouteValues.PublishedRequest.PublishedContent.ContentType.Alias;
string? docTypeAlias = UmbracoRouteValues.PublishedRequest.PublishedContent?.ContentType.Alias;
_logger.LogWarning("No physical template file was found for document type with alias {Alias}", docTypeAlias);
return false;
}