More content refactoring (tests)
This commit is contained in:
@@ -21,9 +21,7 @@ namespace Umbraco.Core.Models
|
||||
internal Action OnAdd;
|
||||
|
||||
internal PropertyGroupCollection()
|
||||
{
|
||||
|
||||
}
|
||||
{ }
|
||||
|
||||
public PropertyGroupCollection(IEnumerable<PropertyGroup> groups)
|
||||
{
|
||||
@@ -38,7 +36,8 @@ namespace Umbraco.Core.Models
|
||||
internal void Reset(IEnumerable<PropertyGroup> groups)
|
||||
{
|
||||
Clear();
|
||||
groups.ForEach(Add);
|
||||
foreach (var group in groups)
|
||||
Add(group);
|
||||
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
|
||||
}
|
||||
|
||||
@@ -74,12 +73,12 @@ namespace Umbraco.Core.Models
|
||||
//Note this is done to ensure existig groups can be renamed
|
||||
if (item.HasIdentity && item.Id > 0)
|
||||
{
|
||||
var exists = this.Contains(item.Id);
|
||||
var exists = Contains(item.Id);
|
||||
if (exists)
|
||||
{
|
||||
var keyExists = this.Contains(item.Name);
|
||||
if(keyExists)
|
||||
throw new Exception(string.Format("Naming conflict: Changing the name of PropertyGroup '{0}' would result in duplicates", item.Name));
|
||||
var keyExists = Contains(item.Name);
|
||||
if (keyExists)
|
||||
throw new Exception($"Naming conflict: Changing the name of PropertyGroup '{item.Name}' would result in duplicates");
|
||||
|
||||
SetItem(IndexOfKey(item.Id), item);
|
||||
return;
|
||||
@@ -90,7 +89,7 @@ namespace Umbraco.Core.Models
|
||||
var key = GetKeyForItem(item);
|
||||
if (key != null)
|
||||
{
|
||||
var exists = this.Contains(key);
|
||||
var exists = Contains(key);
|
||||
if (exists)
|
||||
{
|
||||
SetItem(IndexOfKey(key), item);
|
||||
@@ -100,7 +99,7 @@ namespace Umbraco.Core.Models
|
||||
}
|
||||
|
||||
base.Add(item);
|
||||
OnAdd.IfNotNull(x => x.Invoke());//Could this not be replaced by a Mandate/Contract for ensuring item is not null
|
||||
OnAdd?.Invoke();
|
||||
|
||||
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item));
|
||||
}
|
||||
@@ -132,25 +131,17 @@ namespace Umbraco.Core.Models
|
||||
|
||||
public int IndexOfKey(string key)
|
||||
{
|
||||
for (var i = 0; i < this.Count; i++)
|
||||
{
|
||||
for (var i = 0; i < Count; i++)
|
||||
if (this[i].Name == key)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int IndexOfKey(int id)
|
||||
{
|
||||
for (var i = 0; i < this.Count; i++)
|
||||
{
|
||||
for (var i = 0; i < Count; i++)
|
||||
if (this[i].Id == id)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -163,20 +154,17 @@ namespace Umbraco.Core.Models
|
||||
|
||||
protected virtual void OnCollectionChanged(NotifyCollectionChangedEventArgs args)
|
||||
{
|
||||
if (CollectionChanged != null)
|
||||
{
|
||||
CollectionChanged(this, args);
|
||||
}
|
||||
CollectionChanged?.Invoke(this, args);
|
||||
}
|
||||
|
||||
public object DeepClone()
|
||||
{
|
||||
var newGroup = new PropertyGroupCollection();
|
||||
foreach (var p in this)
|
||||
var clone = new PropertyGroupCollection();
|
||||
foreach (var group in this)
|
||||
{
|
||||
newGroup.Add((PropertyGroup)p.DeepClone());
|
||||
clone.Add((PropertyGroup) group.DeepClone());
|
||||
}
|
||||
return newGroup;
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user