Make views compatible with Nullable Reference Types (#11370)

This commit is contained in:
Jason Elkin
2022-02-27 08:10:08 +00:00
committed by GitHub
parent 9121879e1a
commit b56f0f7062
26 changed files with 62 additions and 60 deletions

View File

@@ -1,6 +1,6 @@
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<Umbraco.Cms.Core.Models.Blocks.BlockListModel>
@{
if (!Model.Any()) { return; }
if (Model?.Any() != true) { return; }
}
<div class="umb-block-list">
@foreach (var block in Model)

View File

@@ -7,7 +7,7 @@
Razor helpers located at the bottom of this file
*@
@if (Model != null && Model.GetType() == typeof(JObject) && Model.sections != null)
@if (Model is JObject && Model?.sections is not null)
{
var oneColumn = ((System.Collections.ICollection)Model.sections).Count == 1;
@@ -55,7 +55,7 @@
<div @RenderElementAttributes(area)>
@foreach (var control in area.controls)
{
if (control != null && control.editor != null && control.editor.view != null)
if (control?.editor?.view != null)
{
<text>@await Html.PartialAsync("grid/editors/base", (object)control)</text>
}

View File

@@ -3,9 +3,9 @@
@using Newtonsoft.Json.Linq
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<dynamic>
@if (Model != null && Model.GetType() == typeof(JObject) && Model.sections != null)
@if (Model is JObject && Model?.sections is not null)
{
var oneColumn = ((System.Collections.ICollection)Model.sections).Count == 1;
var oneColumn = ((System.Collections.ICollection)Model.sections).Count == 1;
<div class="umb-grid">
@if (oneColumn)
@@ -56,7 +56,7 @@
<div @RenderElementAttributes(area)>
@foreach (var control in area.controls)
{
if (control != null && control.editor != null && control.editor.view != null)
if (control?.editor?.view != null)
{
<text>@await Html.PartialAsync("grid/editors/base", (object)control)</text>
}

View File

@@ -3,7 +3,7 @@
@try
{
string editor = EditorView(Model);
<text>@await Html.PartialAsync(editor, (object)Model)</text>
<text>@await Html.PartialAsync(editor, Model as object)</text>
}
catch (Exception ex)
{

View File

@@ -1,10 +1,11 @@
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<dynamic>
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<dynamic>
@{
string embedValue = Convert.ToString(Model.value);
embedValue = embedValue.DetectIsJson() ? Model.value.preview : Model.value;
@if (Model is not null)
{
string embedValue = Convert.ToString(Model.value);
embedValue = embedValue.DetectIsJson() ? Model.value.preview : Model.value;
<div class="video-wrapper">
@Html.Raw(embedValue)
</div>
}
<div class="video-wrapper">
@Html.Raw(embedValue)
</div>

View File

@@ -1,6 +1,6 @@
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<dynamic>
@if (Model.value != null)
@if (Model?.value is not null)
{
string macroAlias = Model.value.macroAlias.ToString();
var parameters = new Dictionary<string,object>();

View File

@@ -2,7 +2,8 @@
@using Umbraco.Cms.Core.Media
@using Umbraco.Cms.Core.PropertyEditors.ValueConverters
@inject IImageUrlGenerator ImageUrlGenerator
@if (Model.value != null)
@if (Model?.value is not null)
{
var url = Model.value.image;

View File

@@ -5,7 +5,7 @@
@inject HtmlImageSourceParser HtmlImageSourceParser;
@{
var value = HtmlLocalLinkParser.EnsureInternalLinks(Model.value.ToString());
var value = HtmlLocalLinkParser.EnsureInternalLinks(Model?.value.ToString());
value = HtmlUrlParser.EnsureUrls(value);
value = HtmlImageSourceParser.EnsureImageSources(value);
}

View File

@@ -1,7 +1,7 @@
@using System.Web
@using System.Web
@model dynamic
@if (Model.editor.config.markup != null)
@if (Model?.editor.config.markup is not null)
{
string markup = Model.editor.config.markup.ToString();
markup = markup.Replace("#value#", Html.ReplaceLineBreaks((string)Model.value.ToString()).ToString());
@@ -18,6 +18,6 @@
else
{
<text>
<div style="@Model.editor.config.style">@Model.value</div>
<div style="@Model?.editor.config.style">@Model?.value</div>
</text>
}

View File

@@ -1,4 +1,4 @@
@using Umbraco.Cms.Core.Routing
@using Umbraco.Cms.Core.Routing
@using Umbraco.Extensions
@inherits Umbraco.Cms.Web.Common.Macros.PartialViewMacroPage
@inject IPublishedUrlProvider PublishedUrlProvider
@@ -10,9 +10,9 @@
- Finally it outputs the name of the current page (without a link)
*@
@{ var selection = Model.Content.Ancestors().ToArray(); }
@{ var selection = Model?.Content.Ancestors().ToArray(); }
@if (selection.Length > 0)
@if (selection?.Length > 0)
{
<ul class="breadcrumb">
@* For each page in the ancestors collection which have been ordered by Level (so we start with the highest top node first) *@
@@ -22,6 +22,6 @@
}
@* Display the current page as the last item in the list *@
<li class="active">@Model.Content.Name</li>
<li class="active">@Model?.Content.Name</li>
</ul>
}

View File

@@ -24,7 +24,7 @@
Type: (note: You can use a Single Media Picker if that's more appropriate to your needs)
*@
@{ var mediaIds = Model.MacroParameters["mediaIds"] as string; }
@{ var mediaIds = Model?.MacroParameters["mediaIds"] as string; }
@if (mediaIds != null)
{

View File

@@ -10,9 +10,9 @@
- Finally it outputs the name of the current page (without a link)
*@
@{ var selection = Model.Content.Ancestors().ToArray(); }
@{ var selection = Model?.Content.Ancestors().ToArray(); }
@if (selection.Length > 0)
@if (selection?.Length > 0)
{
<ul>
@* For each page in the ancestors collection which have been ordered by Level (so we start with the highest top node first) *@
@@ -22,6 +22,6 @@
}
@* Display the current page as the last item in the list *@
<li>@Model.Content.Name</li>
<li>@Model?.Content.Name</li>
</ul>
}

View File

@@ -18,7 +18,7 @@
Alias:startNodeId Name:Select starting page Type:Content Picker
*@
@{ var startNodeId = Model.MacroParameters["startNodeId"]; }
@{ var startNodeId = Model?.MacroParameters["startNodeId"]; }
@if (startNodeId != null)
{

View File

@@ -13,9 +13,9 @@
- It then generates links so the visitor can go to each page
*@
@{ var selection = Model.Content.Children.Where(x => x.IsVisible(PublishedValueFallback)).ToArray(); }
@{ var selection = Model?.Content.Children.Where(x => x.IsVisible(PublishedValueFallback)).ToArray(); }
@if (selection.Length > 0)
@if (selection?.Length > 0)
{
<ul>
@foreach (var item in selection)

View File

@@ -14,9 +14,9 @@
- It then generates links so the visitor can go to each page
*@
@{ var selection = Model.Content.Children.Where(x => x.IsVisible(PublishedValueFallback)).OrderByDescending(x => x.CreateDate).ToArray(); }
@{ var selection = Model?.Content.Children.Where(x => x.IsVisible(PublishedValueFallback)).OrderByDescending(x => x.CreateDate).ToArray(); }
@if (selection.Length > 0)
@if (selection?.Length > 0)
{
<ul>
@foreach (var item in selection)

View File

@@ -14,9 +14,9 @@
- It then generates links so the visitor can go to each page
*@
@{ var selection = Model.Content.Children.Where(x => x.IsVisible(PublishedValueFallback)).OrderBy(x => x.Name).ToArray(); }
@{ var selection = Model?.Content.Children.Where(x => x.IsVisible(PublishedValueFallback)).OrderBy(x => x.Name).ToArray(); }
@if (selection.Length > 0)
@if (selection?.Length > 0)
{
<ul>
@foreach (var item in selection)

View File

@@ -17,13 +17,13 @@
Alias:propertyAlias Name:Property Alias Type:Textbox
*@
@{ var propertyAlias = Model.MacroParameters["propertyAlias"]; }
@{ var propertyAlias = Model?.MacroParameters["propertyAlias"]; }
@if (propertyAlias != null)
{
var selection = Model.Content.Children.Where(x => x.IsVisible(PublishedValueFallback)).OrderBy(x => x.Value(PublishedValueFallback, propertyAlias.ToString())).ToArray();
var selection = Model?.Content.Children.Where(x => x.IsVisible(PublishedValueFallback)).OrderBy(x => x.Value(PublishedValueFallback, propertyAlias.ToString())).ToArray();
if (selection.Length > 0)
if (selection?.Length > 0)
{
<ul>
@foreach (var item in selection)

View File

@@ -13,9 +13,9 @@
(You can find the alias of your Document Type by editing it in the Settings section)
*@
@{ var selection = Model.Content.Children<IPublishedContent>(VariationContextAccessor).Where(x => x.IsVisible(PublishedValueFallback)).ToArray(); }
@{ var selection = Model?.Content.Children<IPublishedContent>(VariationContextAccessor).Where(x => x.IsVisible(PublishedValueFallback)).ToArray(); }
@if (selection.Length > 0)
@if (selection?.Length > 0)
{
<ul>
@foreach (var item in selection)

View File

@@ -10,10 +10,10 @@
the page currently being viewed by the website visitor, displayed as nested unordered HTML lists.
*@
@{ var selection = Model.Content.Children.Where(x => x.IsVisible(PublishedValueFallback)).ToArray(); }
@{ var selection = Model?.Content.Children.Where(x => x.IsVisible(PublishedValueFallback)).ToArray(); }
@* Ensure that the Current Page has children *@
@if (selection.Length > 0)
@if (selection?.Length > 0)
{
@* Get the first page in the children, where the property umbracoNaviHide is not True *@
var naviLevel = selection[0].Level;

View File

@@ -16,7 +16,7 @@
Alias:mediaId Name:Select folder with images Type:Single Media Picker
*@
@{ var mediaId = Model.MacroParameters["mediaId"]; }
@{ var mediaId = Model?.MacroParameters["mediaId"]; }
@if (mediaId != null)
{

View File

@@ -15,7 +15,7 @@
{
<div class="login-status">
<p>Welcome back <strong>@Context.User.Identity.Name</strong>!</p>
<p>Welcome back <strong>@Context?.User?.Identity?.Name</strong>!</p>
@using (Html.BeginUmbracoForm<UmbLoginStatusController>("HandleLogout", new { RedirectUrl = logoutModel.RedirectUrl }))
{

View File

@@ -12,9 +12,9 @@
multinode treepicker (so: replace "PropertyWithPicker" with the alias of your property).
*@
@{ var selection = Model.Content.Value<IEnumerable<IPublishedContent>>(PublishedValueFallback, "PropertyWithPicker").ToArray(); }
@{ var selection = Model?.Content.Value<IEnumerable<IPublishedContent>>(PublishedValueFallback, "PropertyWithPicker").ToArray(); }
@if (selection.Length > 0)
@if (selection?.Length > 0)
{
<ul>
@foreach (var item in selection)

View File

@@ -11,14 +11,14 @@
It also highlights the current active page/section in the navigation with the CSS class "current".
*@
@{ var selection = Model.Content.Root().Children.Where(x => x.IsVisible(PublishedValueFallback)).ToArray(); }
@{ var selection = Model?.Content.Root().Children.Where(x => x.IsVisible(PublishedValueFallback)).ToArray(); }
@if (selection.Length > 0)
@if (selection?.Length > 0)
{
<ul>
@foreach (var item in selection)
{
<li class="@(item.IsAncestorOrSelf(Model.Content) ? "current" : null)">
<li class="@(item.IsAncestorOrSelf(Model?.Content) ? "current" : null)">
<a href="@item.Url(PublishedUrlProvider)">@item.Name</a>
</li>
}

View File

@@ -12,7 +12,7 @@
- It uses a local method called Traverse() to select and display the markup and links.
*@
@{ var selection = Model.Content.Root(); }
@{ var selection = Model?.Content.Root(); }
<div class="sitemap">
@* Render the sitemap by passing the root node to the traverse method, below *@
@@ -21,16 +21,16 @@
@* Helper method to traverse through all descendants *@
@{
void Traverse(IPublishedContent node)
void Traverse(IPublishedContent? node)
{
//Update the level to reflect how deep you want the sitemap to go
const int maxLevelForSitemap = 4;
@* Select visible children *@
var selection = node.Children.Where(x => x.IsVisible(PublishedValueFallback) && x.Level <= maxLevelForSitemap).ToArray();
var selection = node?.Children.Where(x => x.IsVisible(PublishedValueFallback) && x.Level <= maxLevelForSitemap).ToArray();
@* If any items are returned, render a list *@
if (selection.Length > 0)
if (selection?.Length > 0)
{
<ul>
@foreach (var item in selection)

View File

@@ -1,4 +1,4 @@
@using Microsoft.Extensions.Options;
@using Microsoft.Extensions.Options;
@using Umbraco.Cms.Core.Configuration
@using Umbraco.Cms.Core.Configuration.Models
@using Umbraco.Cms.Core.Hosting
@@ -20,7 +20,7 @@
@model Umbraco.Cms.Core.Editors.BackOfficePreviewModel
@{
var disableDevicePreview = Model.DisableDevicePreview.ToString().ToLowerInvariant();
var disableDevicePreview = Model?.DisableDevicePreview.ToString().ToLowerInvariant();
var EndLabel = LocalizedTextService.Localize("preview", "endLabel");
var EndTitle = LocalizedTextService.Localize("preview", "endTitle");
@@ -53,7 +53,7 @@
<body id="canvasdesignerPanel" ng-mouseover="outlinePositionHide()" ng-controller="previewController" ng-class="{'tabbing-active': tabbingActive === true}" ng-click="windowClickHandler($event)">
<div class="wait" ng-show="!frameLoaded"></div>
@if (!string.IsNullOrWhiteSpace(Model.PreviewExtendedHeaderView))
@if (!string.IsNullOrWhiteSpace(Model?.PreviewExtendedHeaderView))
{
@await Html.PartialAsync(Model.PreviewExtendedHeaderView)
}
@@ -77,7 +77,7 @@
</div>
</div>
@if (Model.Languages != null && Model.Languages.Count() > 1)
@if (Model?.Languages.Any() == true)
{
<div class="preview-menu-option" ng-class="{'--open': cultureOpen === true}" ng-click="$event.stopPropagation()">
<button class="menu-bar__button umb-outline" ng-click="toggleCultureOpen()"><i class="icon icon-globe-europe---africa"></i><span>{{currentCulture.title}}</span></button>

View File

@@ -1,4 +1,4 @@
@using Microsoft.Extensions.Options
@using Microsoft.Extensions.Options
@using Umbraco.Cms.Core.Configuration.Models
@using Umbraco.Cms.Core.Hosting
@using Umbraco.Cms.Core.Routing
@@ -31,7 +31,7 @@
<h3>You're seeing this wonderful page because your website doesn't contain any published content yet.</h3>
<div class="cta">
<a href="@Model.UmbracoPath" class="button">Open Umbraco</a>
<a href="@Model?.UmbracoPath" class="button">Open Umbraco</a>
</div>
<div class="row">