Skip to content

Commit

Permalink
Set _items in the ShapeViewModel to prevent exception (#14899)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek authored Dec 14, 2023
1 parent 5a26240 commit b1cfb0d
Showing 1 changed file with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,50 +16,49 @@ 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
{
get
{
return Metadata.Position;
}

get => Metadata.Position;
set
{
Metadata.Position = value;
}
}

public string Id { get; set; }

public string TagName { get; set; }

private List<string> _classes;
public IList<string> Classes => _classes ??= new List<string>();

public IList<string> Classes => _classes ??= [];

private Dictionary<string, string> _attributes;
public IDictionary<string, string> Attributes => _attributes ??= new Dictionary<string, string>();

public IDictionary<string, string> Attributes => _attributes ??= [];

private Dictionary<string, object> _properties;
public IDictionary<string, object> Properties => _properties ??= new Dictionary<string, object>();

public IDictionary<string, object> Properties => _properties ??= [];

private bool _sorted = false;

private List<IPositioned> _items;

public IReadOnlyList<IPositioned> Items
{
get
{
_items ??= new List<IPositioned>();
_items ??= [];

if (!_sorted)
{
Expand All @@ -78,8 +77,9 @@ public ValueTask<IShape> AddAsync(object item, string position)
return new ValueTask<IShape>(this);
}

position ??= "";
position ??= string.Empty;
_sorted = false;
_items ??= [];

if (item is IHtmlContent)
{
Expand All @@ -91,8 +91,7 @@ public ValueTask<IShape> AddAsync(object item, string position)
}
else
{
var shape = item as IPositioned;
if (shape != null)
if (item is IPositioned shape)
{
if (position != null)
{
Expand Down

0 comments on commit b1cfb0d

Please sign in to comment.