Cleans up IProperty

This commit is contained in:
Shannon
2019-11-13 12:17:09 +11:00
parent 319376d157
commit 995b31b86c
6 changed files with 63 additions and 91 deletions

View File

@@ -47,8 +47,7 @@ namespace Umbraco.Core.Collections
var newList = new DeepCloneableList<T>(ListCloneBehavior.None);
foreach (var item in this)
{
var dc = item as IDeepCloneable;
if (dc != null)
if (item is IDeepCloneable dc)
{
newList.Add((T)dc.DeepClone());
}
@@ -66,8 +65,7 @@ namespace Umbraco.Core.Collections
var newList2 = new DeepCloneableList<T>(ListCloneBehavior.Always);
foreach (var item in this)
{
var dc = item as IDeepCloneable;
if (dc != null)
if (item is IDeepCloneable dc)
{
newList2.Add((T)dc.DeepClone());
}
@@ -121,6 +119,16 @@ namespace Umbraco.Core.Collections
}
}
public void DisableChangeTracking()
{
// noop
}
public void EnableChangeTracking()
{
// noop
}
public void ResetWereDirtyProperties()
{
foreach (var dc in this.OfType<IRememberBeingDirty>())

View File

@@ -146,6 +146,16 @@ namespace Umbraco.Core.Models.Entities
throw new WontImplementException();
}
public void DisableChangeTracking()
{
// noop
}
public void EnableChangeTracking()
{
// noop
}
public bool WasDirty()
{
throw new WontImplementException();

View File

@@ -26,5 +26,15 @@ namespace Umbraco.Core.Models.Entities
/// Resets dirty properties.
/// </summary>
void ResetDirtyProperties();
/// <summary>
/// Disables change tracking.
/// </summary>
void DisableChangeTracking();
/// <summary>
/// Enables change tracking.
/// </summary>
void EnableChangeTracking();
}
}

View File

@@ -4,7 +4,7 @@ using Umbraco.Core.Models.Entities;
namespace Umbraco.Core.Models
{
public interface IProperty
public interface IProperty : IEntity, IRememberBeingDirty
{
ValueStorageType ValueStorageType { get; }
@@ -23,24 +23,6 @@ namespace Umbraco.Core.Models
/// </summary>
string Alias { get; }
/// <inheritdoc />
int Id { get; set; }
/// <inheritdoc />
Guid Key { get; set; }
/// <inheritdoc />
DateTime CreateDate { get; set; }
/// <inheritdoc />
DateTime UpdateDate { get; set; }
/// <inheritdoc />
DateTime? DeleteDate { get; set; } // no change tracking - not persisted
/// <inheritdoc />
bool HasIdentity { get; }
/// <summary>
/// Gets the value.
/// </summary>
@@ -56,49 +38,6 @@ namespace Umbraco.Core.Models
/// </summary>
void ResetIdentity();
bool Equals(EntityBase other);
bool Equals(object obj);
int GetHashCode();
object DeepClone();
/// <inheritdoc />
bool IsDirty();
/// <inheritdoc />
bool IsPropertyDirty(string propertyName);
/// <inheritdoc />
IEnumerable<string> GetDirtyProperties();
/// <inheritdoc />
/// <remarks>Saves dirty properties so they can be checked with WasDirty.</remarks>
void ResetDirtyProperties();
/// <inheritdoc />
bool WasDirty();
/// <inheritdoc />
bool WasPropertyDirty(string propertyName);
/// <inheritdoc />
void ResetWereDirtyProperties();
/// <inheritdoc />
void ResetDirtyProperties(bool rememberDirty);
/// <inheritdoc />
IEnumerable<string> GetWereDirtyProperties();
/// <summary>
/// Disables change tracking.
/// </summary>
void DisableChangeTracking();
/// <summary>
/// Enables change tracking.
/// </summary>
void EnableChangeTracking();
int PropertyTypeId { get; }
void PublishValues(string culture = "*", string segment = "*");
void UnpublishValues(string culture = "*", string segment = "*");

View File

@@ -105,6 +105,7 @@ namespace Umbraco.Core.Models
// we have to have all this, because we're an IUmbracoEntity, because that is
// required by the query expression visitor / SimpleContentTypeMapper
// TODO: Make the query expression visitor use a different common interface, or investigate removing IRememberBeingDirty from being a requirement on that interface and expliclty checking for that throughout the code?
string ITreeEntity.Name { get => this.Name; set => throw new NotImplementedException(); }
int IEntity.Id { get => this.Id; set => throw new NotImplementedException(); }
@@ -130,5 +131,7 @@ namespace Umbraco.Core.Models
bool ICanBeDirty.IsPropertyDirty(string propName) => throw new NotImplementedException();
IEnumerable<string> ICanBeDirty.GetDirtyProperties() => throw new NotImplementedException();
void ICanBeDirty.ResetDirtyProperties() => throw new NotImplementedException();
public void DisableChangeTracking() => throw new NotImplementedException();
public void EnableChangeTracking() => throw new NotImplementedException();
}
}

View File

@@ -11,6 +11,7 @@ namespace Umbraco.Tests.Models.Collections
{
public abstract class Item : IEntity, ICanBeDirty
{
private bool _withChanges = true; // should we track changes?
private bool _hasIdentity;
private int _id;
private Guid _key;
@@ -26,10 +27,7 @@ namespace Umbraco.Tests.Models.Collections
[DataMember]
public int Id
{
get
{
return _id;
}
get => _id;
set
{
_id = value;
@@ -45,14 +43,8 @@ namespace Umbraco.Tests.Models.Collections
[DataMember]
public Guid Key
{
get
{
if (_key == Guid.Empty)
return _id.ToGuid();
return _key;
}
set { _key = value; }
get => _key == Guid.Empty ? _id.ToGuid() : _key;
set => _key = value;
}
/// <summary>
@@ -93,12 +85,12 @@ namespace Umbraco.Tests.Models.Collections
/// <param name="propertyInfo">The property info.</param>
protected virtual void OnPropertyChanged(PropertyInfo propertyInfo)
{
if (_withChanges == false)
return;
_propertyChangedInfo[propertyInfo.Name] = true;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyInfo.Name));
}
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyInfo.Name));
}
internal virtual void ResetIdentity()
@@ -128,7 +120,7 @@ namespace Umbraco.Tests.Models.Collections
/// Tracks the properties that have changed
/// </summary>
//private readonly IDictionary<string, bool> _propertyChangedInfo = new Dictionary<string, bool>();
private IDictionary<string, bool> _propertyChangedInfo;
private readonly IDictionary<string, bool> _propertyChangedInfo;
/// <summary>
/// Indicates whether a specific property on the current entity is dirty.
@@ -166,19 +158,29 @@ namespace Umbraco.Tests.Models.Collections
_propertyChangedInfo.Clear();
}
/// <summary>
/// Disables change tracking.
/// </summary>
public void DisableChangeTracking()
{
_withChanges = false;
}
/// <summary>
/// Enables change tracking.
/// </summary>
public void EnableChangeTracking()
{
_withChanges = true;
}
/// <summary>
/// Indicates whether the current entity has an identity, eg. Id.
/// </summary>
public virtual bool HasIdentity
{
get
{
return _hasIdentity;
}
protected set
{
_hasIdentity = value;
}
get => _hasIdentity;
protected set => _hasIdentity = value;
}
public static bool operator ==(Item left, Item right)