From 13498deb4f35ddddb355d6d3105fe64c6d9b661e Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Mon, 25 Nov 2024 01:16:37 +0300 Subject: [PATCH] Remove unnecessary null check --- .../Controllers/AdminController.cs | 13 +++++------- .../ContentFieldDisplayDriver.cs | 21 +++++++------------ .../Views/ShapeResult.cs | 15 ++++++------- 3 files changed, 19 insertions(+), 30 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Controllers/AdminController.cs index 53acba8a61a..33f3ba8ff67 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Controllers/AdminController.cs @@ -530,16 +530,13 @@ public async Task DiscardDraft(string contentItemId, string retur return Forbid(); } - if (contentItem != null) - { - await _contentManager.DiscardDraftAsync(contentItem); + await _contentManager.DiscardDraftAsync(contentItem); - var typeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); + var typeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType); - await _notifier.SuccessAsync(string.IsNullOrWhiteSpace(typeDefinition?.DisplayName) - ? H["The draft has been removed."] - : H["The {0} draft has been removed.", typeDefinition.DisplayName]); - } + await _notifier.SuccessAsync(string.IsNullOrWhiteSpace(typeDefinition?.DisplayName) + ? H["The draft has been removed."] + : H["The {0} draft has been removed.", typeDefinition.DisplayName]); return Url.IsLocalUrl(returnUrl) ? this.LocalRedirect(returnUrl, true) diff --git a/src/OrchardCore/OrchardCore.ContentManagement.Display/ContentDisplay/ContentFieldDisplayDriver.cs b/src/OrchardCore/OrchardCore.ContentManagement.Display/ContentDisplay/ContentFieldDisplayDriver.cs index 878d786a34f..007806c25fb 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement.Display/ContentDisplay/ContentFieldDisplayDriver.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement.Display/ContentDisplay/ContentFieldDisplayDriver.cs @@ -166,24 +166,19 @@ Task IContentFieldDisplayDriver.BuildEditorAsync(ContentPart con var field = contentPart.GetOrCreate(partFieldDefinition.Name); - if (field != null) - { - BuildPrefix(typePartDefinition, partFieldDefinition, context.HtmlFieldPrefix); + BuildPrefix(typePartDefinition, partFieldDefinition, context.HtmlFieldPrefix); - var fieldEditorContext = new BuildFieldEditorContext(contentPart, typePartDefinition, partFieldDefinition, context); + var fieldEditorContext = new BuildFieldEditorContext(contentPart, typePartDefinition, partFieldDefinition, context); - _typePartDefinition = typePartDefinition; - _partFieldDefinition = partFieldDefinition; + _typePartDefinition = typePartDefinition; + _partFieldDefinition = partFieldDefinition; - var result = EditAsync(field, fieldEditorContext); + var result = EditAsync(field, fieldEditorContext); - _typePartDefinition = null; - _partFieldDefinition = null; - - return result; - } + _typePartDefinition = null; + _partFieldDefinition = null; - return Task.FromResult(default(IDisplayResult)); + return result; } async Task IContentFieldDisplayDriver.UpdateEditorAsync(ContentPart contentPart, ContentPartFieldDefinition partFieldDefinition, ContentTypePartDefinition typePartDefinition, UpdateEditorContext context) diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/Views/ShapeResult.cs b/src/OrchardCore/OrchardCore.DisplayManagement/Views/ShapeResult.cs index 6cb28855904..691206aee38 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/Views/ShapeResult.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/Views/ShapeResult.cs @@ -187,17 +187,14 @@ private async Task ApplyImplementationAsync(BuildShapeContext context, string di newShapeMetadata.Wrappers.Clear(); } - if (placement != null) + if (placement.Alternates != null) { - if (placement.Alternates != null) - { - newShapeMetadata.Alternates.AddRange(placement.Alternates); - } + newShapeMetadata.Alternates.AddRange(placement.Alternates); + } - if (placement.Wrappers != null) - { - newShapeMetadata.Wrappers.AddRange(placement.Wrappers); - } + if (placement.Wrappers != null) + { + newShapeMetadata.Wrappers.AddRange(placement.Wrappers); } var parentShape = context.Shape;