using System; using System.Collections.Generic; using System.Runtime.Serialization; namespace Umbraco.Cms.Core.Models.Entities { /// /// Implementation of for internal use. /// /// /// Although it implements , this class does not /// implement and everything this interface defines, throws. /// Although it implements , this class does not /// implement and deep-cloning throws. /// public class EntitySlim : IEntitySlim { private IDictionary _additionalData; /// /// Gets an entity representing "root". /// public static readonly IEntitySlim Root = new EntitySlim { Path = "-1", Name = "root", HasChildren = true }; // implement IEntity /// [DataMember] public int Id { get; set; } /// [DataMember] public Guid Key { get; set; } /// [DataMember] public DateTime CreateDate { get; set; } /// [DataMember] public DateTime UpdateDate { get; set; } /// [DataMember] public DateTime? DeleteDate { get; set; } /// [DataMember] public bool HasIdentity => Id != 0; // implement ITreeEntity /// [DataMember] public string Name { get; set; } /// [DataMember] public int CreatorId { get; set; } /// [DataMember] public int ParentId { get; set; } /// public void SetParent(ITreeEntity parent) => throw new InvalidOperationException("This property won't be implemented."); /// [DataMember] public int Level { get; set; } /// [DataMember] public string Path { get; set; } /// [DataMember] public int SortOrder { get; set; } /// [DataMember] public bool Trashed { get; set; } // implement IUmbracoEntity /// [DataMember] public IDictionary AdditionalData => _additionalData ?? (_additionalData = new Dictionary()); /// [IgnoreDataMember] public bool HasAdditionalData => _additionalData != null; // implement IEntitySlim /// [DataMember] public Guid NodeObjectType { get; set; } /// [DataMember] public bool HasChildren { get; set; } /// [DataMember] public virtual bool IsContainer { get; set; } #region IDeepCloneable /// public object DeepClone() { throw new InvalidOperationException("This method won't be implemented."); } #endregion public void ResetIdentity() { Id = default; Key = Guid.Empty; } #region IRememberBeingDirty // IEntitySlim does *not* track changes, but since it indirectly implements IUmbracoEntity, // and therefore IRememberBeingDirty, we have to have those methods - which all throw. public bool IsDirty() { throw new InvalidOperationException("This method won't be implemented."); } public bool IsPropertyDirty(string propName) { throw new InvalidOperationException("This method won't be implemented."); } public IEnumerable GetDirtyProperties() { throw new InvalidOperationException("This method won't be implemented."); } public void ResetDirtyProperties() { throw new InvalidOperationException("This method won't be implemented."); } public bool WasDirty() { throw new InvalidOperationException("This method won't be implemented."); } public bool WasPropertyDirty(string propertyName) { throw new InvalidOperationException("This method won't be implemented."); } public void ResetWereDirtyProperties() { throw new InvalidOperationException("This method won't be implemented."); } public void ResetDirtyProperties(bool rememberDirty) { throw new InvalidOperationException("This method won't be implemented."); } public IEnumerable GetWereDirtyProperties() { throw new InvalidOperationException("This method won't be implemented."); } #endregion } }