Cleans up IPropertyCollection
This commit is contained in:
@@ -3,19 +3,34 @@ using System.Collections.Specialized;
|
||||
|
||||
namespace Umbraco.Core.Models
|
||||
{
|
||||
public interface IPropertyCollection : IEnumerable<IProperty>
|
||||
public interface IPropertyCollection : IEnumerable<IProperty>, IDeepCloneable, INotifyCollectionChanged
|
||||
{
|
||||
bool TryGetValue(string propertyTypeAlias, out IProperty property);
|
||||
bool Contains(string key);
|
||||
|
||||
event NotifyCollectionChangedEventHandler CollectionChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Ensures that the collection contains properties for the specified property types.
|
||||
/// </summary>
|
||||
void EnsurePropertyTypes(IEnumerable<IPropertyType> propertyTypes);
|
||||
void EnsureCleanPropertyTypes(IEnumerable<IPropertyType> propertyTypes);
|
||||
object DeepClone();
|
||||
|
||||
/// <summary>
|
||||
/// Ensures that the collection does not contain properties not in the specified property types.
|
||||
/// </summary>
|
||||
void EnsureCleanPropertyTypes(IEnumerable<IPropertyType> propertyTypes);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the property with the specified alias.
|
||||
/// </summary>
|
||||
IProperty this[string name] { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the property at the specified index.
|
||||
/// </summary>
|
||||
IProperty this[int index] { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Adds or updates a property.
|
||||
/// </summary>
|
||||
void Add(IProperty property);
|
||||
|
||||
int Count { get; }
|
||||
|
||||
@@ -12,12 +12,10 @@ namespace Umbraco.Core.Models
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[DataContract(IsReference = true)]
|
||||
public class PropertyCollection : KeyedCollection<string, IProperty>, INotifyCollectionChanged, IDeepCloneable, IPropertyCollection
|
||||
public class PropertyCollection : KeyedCollection<string, IProperty>, IPropertyCollection
|
||||
{
|
||||
private readonly object _addLocker = new object();
|
||||
|
||||
internal Func<Property, bool> AdditionValidator { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PropertyCollection"/> class.
|
||||
/// </summary>
|
||||
@@ -25,16 +23,6 @@ namespace Umbraco.Core.Models
|
||||
: base(StringComparer.InvariantCultureIgnoreCase)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PropertyCollection"/> class.
|
||||
/// </summary>
|
||||
/// <param name="additionValidator">A function validating added properties.</param>
|
||||
internal PropertyCollection(Func<Property, bool> additionValidator)
|
||||
: this()
|
||||
{
|
||||
AdditionValidator = additionValidator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PropertyCollection"/> class.
|
||||
/// </summary>
|
||||
@@ -47,7 +35,7 @@ namespace Umbraco.Core.Models
|
||||
/// <summary>
|
||||
/// Replaces all properties, whilst maintaining validation delegates.
|
||||
/// </summary>
|
||||
internal void Reset(IEnumerable<Property> properties)
|
||||
private void Reset(IEnumerable<Property> properties)
|
||||
{
|
||||
//collection events will be raised in each of these calls
|
||||
Clear();
|
||||
@@ -95,9 +83,7 @@ namespace Umbraco.Core.Models
|
||||
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds or updates a property.
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public new void Add(IProperty property)
|
||||
{
|
||||
lock (_addLocker) // TODO: why are we locking here and not everywhere else?!
|
||||
@@ -131,7 +117,7 @@ namespace Umbraco.Core.Models
|
||||
/// <summary>
|
||||
/// Gets the index for a specified property alias.
|
||||
/// </summary>
|
||||
public int IndexOfKey(string key)
|
||||
private int IndexOfKey(string key)
|
||||
{
|
||||
for (var i = 0; i < Count; i++)
|
||||
{
|
||||
@@ -173,9 +159,8 @@ namespace Umbraco.Core.Models
|
||||
CollectionChanged?.Invoke(this, args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensures that the collection contains properties for the specified property types.
|
||||
/// </summary>
|
||||
|
||||
/// <inheritdoc />
|
||||
public void EnsurePropertyTypes(IEnumerable<IPropertyType> propertyTypes)
|
||||
{
|
||||
if (propertyTypes == null)
|
||||
@@ -185,9 +170,8 @@ namespace Umbraco.Core.Models
|
||||
Add(new Property(propertyType));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensures that the collection does not contain properties not in the specified property types.
|
||||
/// </summary>
|
||||
|
||||
/// <inheritdoc />
|
||||
public void EnsureCleanPropertyTypes(IEnumerable<IPropertyType> propertyTypes)
|
||||
{
|
||||
if (propertyTypes == null)
|
||||
|
||||
Reference in New Issue
Block a user