From 757c4f28beaae30225e94a018012f7010318e013 Mon Sep 17 00:00:00 2001 From: Johan Petersson Date: Wed, 22 Nov 2023 09:19:37 +0100 Subject: [PATCH] Some code styling --- .../CustomizedRenderingInitialization.cs | 1 - .../Alloy.Mvc/Business/PageContextActionFilter.cs | 6 ++---- .../Rendering/SiteViewEngineLocationExpander.cs | 6 +++--- .../Business/Rendering/TemplateCoordinator.cs | 8 ++++---- .../UIDescriptors/ContainerPageUIDescriptor.cs | 2 +- .../Alloy.Mvc/Controllers/DefaultPageController.cs | 2 +- .../Alloy.Mvc/Controllers/PreviewController.cs | 2 +- .../Alloy.Mvc/Extensions/ViewContextExtension.cs | 2 +- .../Alloy.Mvc/Helpers/CategorizableExtensions.cs | 4 ++-- templates/Alloy.Mvc/Helpers/UrlHelpers.cs | 1 - templates/Alloy.Mvc/Models/Pages/ProductPage.cs | 4 ++-- templates/Alloy.Mvc/Models/Pages/SearchPage.cs | 2 +- templates/Alloy.Mvc/Models/Pages/StartPage.cs | 13 +++++++------ .../Alloy.Mvc/Models/ViewModels/PreviewModel.cs | 2 +- 14 files changed, 26 insertions(+), 29 deletions(-) diff --git a/templates/Alloy.Mvc/Business/Initialization/CustomizedRenderingInitialization.cs b/templates/Alloy.Mvc/Business/Initialization/CustomizedRenderingInitialization.cs index 9996c8f..4b16a18 100644 --- a/templates/Alloy.Mvc/Business/Initialization/CustomizedRenderingInitialization.cs +++ b/templates/Alloy.Mvc/Business/Initialization/CustomizedRenderingInitialization.cs @@ -4,7 +4,6 @@ using EPiServer.ServiceLocation; using EPiServer.Web; using EPiServer.Web.Mvc; -using EPiServer.Web.Mvc.Html; namespace Alloy.Mvc._1.Business.Initialization; diff --git a/templates/Alloy.Mvc/Business/PageContextActionFilter.cs b/templates/Alloy.Mvc/Business/PageContextActionFilter.cs index 20f8ff1..f665731 100644 --- a/templates/Alloy.Mvc/Business/PageContextActionFilter.cs +++ b/templates/Alloy.Mvc/Business/PageContextActionFilter.cs @@ -18,6 +18,7 @@ namespace Alloy.Mvc._1.Business; public class PageContextActionFilter : IResultFilter { private readonly PageViewContextFactory _contextFactory; + public PageContextActionFilter(PageViewContextFactory contextFactory) { _contextFactory = contextFactory; @@ -41,10 +42,7 @@ public void OnResultExecuting(ResultExecutingContext context) model.Layout = layoutModel; - if (model.Section == null) - { - model.Section = _contextFactory.GetSection(currentContentLink); - } + model.Section ??= _contextFactory.GetSection(currentContentLink); } } diff --git a/templates/Alloy.Mvc/Business/Rendering/SiteViewEngineLocationExpander.cs b/templates/Alloy.Mvc/Business/Rendering/SiteViewEngineLocationExpander.cs index 264b21c..f52f99c 100644 --- a/templates/Alloy.Mvc/Business/Rendering/SiteViewEngineLocationExpander.cs +++ b/templates/Alloy.Mvc/Business/Rendering/SiteViewEngineLocationExpander.cs @@ -4,11 +4,11 @@ namespace Alloy.Mvc._1.Business.Rendering; public class SiteViewEngineLocationExpander : IViewLocationExpander { - private static readonly string[] AdditionalPartialViewFormats = new[] - { + private static readonly string[] AdditionalPartialViewFormats = + [ TemplateCoordinator.BlockFolder + "{0}.cshtml", TemplateCoordinator.PagePartialsFolder + "{0}.cshtml" - }; + ]; public IEnumerable ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable viewLocations) { diff --git a/templates/Alloy.Mvc/Business/Rendering/TemplateCoordinator.cs b/templates/Alloy.Mvc/Business/Rendering/TemplateCoordinator.cs index d46b771..f715f90 100644 --- a/templates/Alloy.Mvc/Business/Rendering/TemplateCoordinator.cs +++ b/templates/Alloy.Mvc/Business/Rendering/TemplateCoordinator.cs @@ -1,7 +1,7 @@ -using EPiServer.ServiceLocation; using Alloy.Mvc._1.Controllers; using Alloy.Mvc._1.Models.Blocks; using Alloy.Mvc._1.Models.Pages; +using EPiServer.ServiceLocation; using EPiServer.Web; using EPiServer.Web.Mvc; @@ -40,7 +40,7 @@ public void Register(TemplateModelCollection viewTemplateModelRegistrator) viewTemplateModelRegistrator.Add(typeof(TeaserBlock), new TemplateModel { Name = "TeaserBlockWide", - Tags = new[] { Globals.ContentAreaTags.WideWidth, Globals.ContentAreaTags.FullWidth }, + Tags = [Globals.ContentAreaTags.WideWidth, Globals.ContentAreaTags.FullWidth], AvailableWithoutTag = false, }); @@ -56,7 +56,7 @@ public void Register(TemplateModelCollection viewTemplateModelRegistrator) { Name = "PageWide", Inherit = true, - Tags = new[] { Globals.ContentAreaTags.WideWidth, Globals.ContentAreaTags.FullWidth }, + Tags = [Globals.ContentAreaTags.WideWidth, Globals.ContentAreaTags.FullWidth], AvailableWithoutTag = false, Path = PagePartialPath("PageWide.cshtml") }); @@ -65,7 +65,7 @@ public void Register(TemplateModelCollection viewTemplateModelRegistrator) { Name = "NoRenderer", Inherit = true, - Tags = new[] { Globals.ContentAreaTags.NoRenderer }, + Tags = [Globals.ContentAreaTags.NoRenderer], AvailableWithoutTag = false, Path = BlockPath("NoRenderer.cshtml") }); diff --git a/templates/Alloy.Mvc/Business/UIDescriptors/ContainerPageUIDescriptor.cs b/templates/Alloy.Mvc/Business/UIDescriptors/ContainerPageUIDescriptor.cs index 70c1786..cf43af7 100644 --- a/templates/Alloy.Mvc/Business/UIDescriptors/ContainerPageUIDescriptor.cs +++ b/templates/Alloy.Mvc/Business/UIDescriptors/ContainerPageUIDescriptor.cs @@ -1,5 +1,5 @@ -using EPiServer.Shell; using Alloy.Mvc._1.Models.Pages; +using EPiServer.Shell; namespace Alloy.Mvc._1.Business.UIDescriptors; diff --git a/templates/Alloy.Mvc/Controllers/DefaultPageController.cs b/templates/Alloy.Mvc/Controllers/DefaultPageController.cs index 2e4bf89..0c19851 100644 --- a/templates/Alloy.Mvc/Controllers/DefaultPageController.cs +++ b/templates/Alloy.Mvc/Controllers/DefaultPageController.cs @@ -1,6 +1,6 @@ -using EPiServer.Framework.DataAnnotations; using Alloy.Mvc._1.Models.Pages; using Alloy.Mvc._1.Models.ViewModels; +using EPiServer.Framework.DataAnnotations; using Microsoft.AspNetCore.Mvc; namespace Alloy.Mvc._1.Controllers; diff --git a/templates/Alloy.Mvc/Controllers/PreviewController.cs b/templates/Alloy.Mvc/Controllers/PreviewController.cs index f4bfd01..69fa29d 100644 --- a/templates/Alloy.Mvc/Controllers/PreviewController.cs +++ b/templates/Alloy.Mvc/Controllers/PreviewController.cs @@ -17,7 +17,7 @@ namespace Alloy.Mvc._1.Controllers; [TemplateDescriptor( Inherited = true, TemplateTypeCategory = TemplateTypeCategories.MvcController, //Required as controllers for blocks are registered as MvcPartialController by default - Tags = new[] { RenderingTags.Preview, RenderingTags.Edit }, + Tags = [RenderingTags.Preview, RenderingTags.Edit], AvailableWithoutTag = false)] [VisitorGroupImpersonation] [RequireClientResources] diff --git a/templates/Alloy.Mvc/Extensions/ViewContextExtension.cs b/templates/Alloy.Mvc/Extensions/ViewContextExtension.cs index 622c170..eb85fc2 100644 --- a/templates/Alloy.Mvc/Extensions/ViewContextExtension.cs +++ b/templates/Alloy.Mvc/Extensions/ViewContextExtension.cs @@ -16,7 +16,7 @@ public static class ViewContextExtension /// /// public static bool IsPreviewMode(this ViewContext viewContext) - => viewContext.IsInEditMode() && (viewContext.ActionDescriptor as ControllerActionDescriptor)?.ControllerName == "Preview"; + => viewContext.IsInEditMode() && viewContext.ActionDescriptor is ControllerActionDescriptor { ControllerName: "Preview" }; /// /// Determines if the request context is in edit mode. diff --git a/templates/Alloy.Mvc/Helpers/CategorizableExtensions.cs b/templates/Alloy.Mvc/Helpers/CategorizableExtensions.cs index 6079b25..1095b8c 100644 --- a/templates/Alloy.Mvc/Helpers/CategorizableExtensions.cs +++ b/templates/Alloy.Mvc/Helpers/CategorizableExtensions.cs @@ -18,7 +18,7 @@ public static string[] GetThemeCssClassNames(this ICategorizable content) { if (content.Category == null) { - return Array.Empty(); + return []; } // Although with some overhead, a HashSet allows us to ensure we never add a CSS class more than once @@ -43,6 +43,6 @@ public static string[] GetThemeCssClassNames(this ICategorizable content) } } - return cssClasses.ToArray(); + return [.. cssClasses]; } } diff --git a/templates/Alloy.Mvc/Helpers/UrlHelpers.cs b/templates/Alloy.Mvc/Helpers/UrlHelpers.cs index 034452d..ac95c0b 100644 --- a/templates/Alloy.Mvc/Helpers/UrlHelpers.cs +++ b/templates/Alloy.Mvc/Helpers/UrlHelpers.cs @@ -1,5 +1,4 @@ using EPiServer.ServiceLocation; -using EPiServer.Shell.Navigation; using EPiServer.Web.Routing; using Microsoft.AspNetCore.Mvc; diff --git a/templates/Alloy.Mvc/Models/Pages/ProductPage.cs b/templates/Alloy.Mvc/Models/Pages/ProductPage.cs index 4e5e913..49398cd 100644 --- a/templates/Alloy.Mvc/Models/Pages/ProductPage.cs +++ b/templates/Alloy.Mvc/Models/Pages/ProductPage.cs @@ -12,7 +12,7 @@ namespace Alloy.Mvc._1.Models.Pages; [SiteImageUrl(Globals.StaticGraphicsFolderPath + "page-type-thumbnail-product.png")] [AvailableContentTypes( Availability = Availability.Specific, - IncludeOn = new[] { typeof(StartPage) })] + IncludeOn = [typeof(StartPage)])] public class ProductPage : StandardPage, IHasRelatedContent { [Required] @@ -25,6 +25,6 @@ public class ProductPage : StandardPage, IHasRelatedContent GroupName = SystemTabNames.Content, Order = 330)] [CultureSpecific] - [AllowedTypes(new[] { typeof(IContentData) }, new[] { typeof(JumbotronBlock) })] + [AllowedTypes([typeof(IContentData)], [typeof(JumbotronBlock)])] public virtual ContentArea RelatedContentArea { get; set; } } diff --git a/templates/Alloy.Mvc/Models/Pages/SearchPage.cs b/templates/Alloy.Mvc/Models/Pages/SearchPage.cs index b2e5ff5..36d2463 100644 --- a/templates/Alloy.Mvc/Models/Pages/SearchPage.cs +++ b/templates/Alloy.Mvc/Models/Pages/SearchPage.cs @@ -16,6 +16,6 @@ public class SearchPage : SitePageData, IHasRelatedContent, ISearchPage GroupName = SystemTabNames.Content, Order = 310)] [CultureSpecific] - [AllowedTypes(new[] { typeof(IContentData) }, new[] { typeof(JumbotronBlock) })] + [AllowedTypes([typeof(IContentData)], [typeof(JumbotronBlock)])] public virtual ContentArea RelatedContentArea { get; set; } } diff --git a/templates/Alloy.Mvc/Models/Pages/StartPage.cs b/templates/Alloy.Mvc/Models/Pages/StartPage.cs index 8fbf566..fc41681 100644 --- a/templates/Alloy.Mvc/Models/Pages/StartPage.cs +++ b/templates/Alloy.Mvc/Models/Pages/StartPage.cs @@ -13,22 +13,23 @@ namespace Alloy.Mvc._1.Models.Pages; [SiteImageUrl] [AvailableContentTypes( Availability.Specific, - Include = new[] - { + Include = + [ typeof(ContainerPage), typeof(ProductPage), typeof(StandardPage), typeof(ISearchPage), typeof(LandingPage), - typeof(ContentFolder) }, // Pages we can create under the start page... - ExcludeOn = new[] - { + typeof(ContentFolder) + ], // Pages we can create under the start page... + ExcludeOn = + [ typeof(ContainerPage), typeof(ProductPage), typeof(StandardPage), typeof(ISearchPage), typeof(LandingPage) - })] // ...and underneath those we can't create additional start pages + ])] // ...and underneath those we can't create additional start pages public class StartPage : SitePageData { [Display( diff --git a/templates/Alloy.Mvc/Models/ViewModels/PreviewModel.cs b/templates/Alloy.Mvc/Models/ViewModels/PreviewModel.cs index 4adc9f2..9fe3bb5 100644 --- a/templates/Alloy.Mvc/Models/ViewModels/PreviewModel.cs +++ b/templates/Alloy.Mvc/Models/ViewModels/PreviewModel.cs @@ -13,7 +13,7 @@ public PreviewModel(SitePageData currentPage, IContent previewContent) public IContent PreviewContent { get; set; } - public List Areas { get; set; } + public List Areas { get; set; } = []; public class PreviewArea {