From ea52bd6577623c215bdc17678963dfbbdb374ccb Mon Sep 17 00:00:00 2001 From: James Hawkins Date: Wed, 27 Feb 2019 11:02:55 -0500 Subject: [PATCH 1/2] Initialize content picker field with empty array --- .../Drivers/ContentPickerFieldDisplayDriver.cs | 4 ++-- .../OrchardCore.ContentFields/Fields/ContentPickerField.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Drivers/ContentPickerFieldDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Drivers/ContentPickerFieldDisplayDriver.cs index 0753bf3c902..bfa8ab26c49 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Drivers/ContentPickerFieldDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Drivers/ContentPickerFieldDisplayDriver.cs @@ -50,7 +50,7 @@ public override IDisplayResult Edit(ContentPickerField field, BuildFieldEditorCo { return Initialize(GetEditorShapeType(context), async model => { - model.ContentItemIds = field.ContentItemIds == null ? string.Empty : string.Join(",", field.ContentItemIds); + model.ContentItemIds = string.Join(",", field.ContentItemIds); model.Field = field; model.Part = context.ContentPart; @@ -58,7 +58,7 @@ public override IDisplayResult Edit(ContentPickerField field, BuildFieldEditorCo model.SelectedItems = new List(); - foreach (var contentItemId in field.ContentItemIds ?? new string[0]) + foreach (var contentItemId in field.ContentItemIds) { var contentItem = await _contentManager.GetAsync(contentItemId, VersionOptions.Latest); diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Fields/ContentPickerField.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Fields/ContentPickerField.cs index e2aa150f756..365537395d4 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Fields/ContentPickerField.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Fields/ContentPickerField.cs @@ -4,6 +4,6 @@ namespace OrchardCore.ContentFields.Fields { public class ContentPickerField : ContentField { - public string[] ContentItemIds { get; set; } + public string[] ContentItemIds { get; set; } = new string[0]; } } From abaa3e2ac85239be20585610c48910864fb7e723 Mon Sep 17 00:00:00 2001 From: James Hawkins Date: Wed, 27 Feb 2019 13:07:07 -0500 Subject: [PATCH 2/2] Use array.empty instead of string[0] --- .../OrchardCore.ContentFields/Fields/ContentPickerField.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Fields/ContentPickerField.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Fields/ContentPickerField.cs index 365537395d4..ac0e10d7189 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Fields/ContentPickerField.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Fields/ContentPickerField.cs @@ -1,9 +1,10 @@ +using System; using OrchardCore.ContentManagement; namespace OrchardCore.ContentFields.Fields { public class ContentPickerField : ContentField { - public string[] ContentItemIds { get; set; } = new string[0]; + public string[] ContentItemIds { get; set; } = Array.Empty(); } }