From fca45ec2caa76693d1c459e2696e5384eac5588e Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Thu, 14 Dec 2023 10:54:29 -0800 Subject: [PATCH 1/3] Set the _items in ShapeViewModel --- .../Views/ShapeViewModel.cs | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/Views/ShapeViewModel.cs b/src/OrchardCore/OrchardCore.DisplayManagement/Views/ShapeViewModel.cs index 6df0449c36c..66bd54dd985 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/Views/ShapeViewModel.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/Views/ShapeViewModel.cs @@ -16,15 +16,13 @@ public ShapeViewModel() public ShapeViewModel(string shapeType) { - if (string.IsNullOrEmpty(shapeType)) - { - throw new ArgumentException($"The {nameof(shapeType)} cannot be empty"); - } + ArgumentException.ThrowIfNullOrEmpty(shapeType, nameof(shapeType)); Metadata.Type = shapeType; } private ShapeMetadata _metadata; + public ShapeMetadata Metadata => _metadata ??= new ShapeMetadata(); public string Position @@ -41,26 +39,29 @@ public string Position } public string Id { get; set; } + public string TagName { get; set; } private List _classes; - public IList Classes => _classes ??= new List(); + + public IList Classes => _classes ??= []; private Dictionary _attributes; - public IDictionary Attributes => _attributes ??= new Dictionary(); + + public IDictionary Attributes => _attributes ??= []; private Dictionary _properties; - public IDictionary Properties => _properties ??= new Dictionary(); + + public IDictionary Properties => _properties ??= []; private bool _sorted = false; - private List _items; + private List _items = []; + public IReadOnlyList Items { get { - _items ??= new List(); - if (!_sorted) { _items = _items.OrderBy(x => x, FlatPositionComparer.Instance).ToList(); @@ -78,7 +79,7 @@ public ValueTask AddAsync(object item, string position) return new ValueTask(this); } - position ??= ""; + position ??= string.Empty; _sorted = false; if (item is IHtmlContent) From 85d45b02a93a64debe4ec21c45efb18342383eec Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Thu, 14 Dec 2023 10:56:48 -0800 Subject: [PATCH 2/3] cleanup --- .../Views/ShapeViewModel.cs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/Views/ShapeViewModel.cs b/src/OrchardCore/OrchardCore.DisplayManagement/Views/ShapeViewModel.cs index 66bd54dd985..57f3db1d4b9 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/Views/ShapeViewModel.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/Views/ShapeViewModel.cs @@ -27,11 +27,7 @@ public ShapeViewModel(string shapeType) public string Position { - get - { - return Metadata.Position; - } - + get => Metadata.Position; set { Metadata.Position = value; @@ -92,8 +88,7 @@ public ValueTask AddAsync(object item, string position) } else { - var shape = item as IPositioned; - if (shape != null) + if (item is IPositioned shape) { if (position != null) { From 55f31f6d47db66b1062d408a1cf31ccb41e681be Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Thu, 14 Dec 2023 11:39:29 -0800 Subject: [PATCH 3/3] initialize on demand --- .../OrchardCore.DisplayManagement/Views/ShapeViewModel.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/Views/ShapeViewModel.cs b/src/OrchardCore/OrchardCore.DisplayManagement/Views/ShapeViewModel.cs index 57f3db1d4b9..109699a581d 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/Views/ShapeViewModel.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/Views/ShapeViewModel.cs @@ -52,12 +52,14 @@ public string Position private bool _sorted = false; - private List _items = []; + private List _items; public IReadOnlyList Items { get { + _items ??= []; + if (!_sorted) { _items = _items.OrderBy(x => x, FlatPositionComparer.Instance).ToList(); @@ -77,6 +79,7 @@ public ValueTask AddAsync(object item, string position) position ??= string.Empty; _sorted = false; + _items ??= []; if (item is IHtmlContent) {