Skip to content

Support classes (abstract) with generic classes #54

@jeffward01

Description

@jeffward01

I have an abstract class called AeonicBaseEntity. this is the errors I see:

image

image

Example of the class:

public abstract partial class AeonicBaseEntity<TEntity, TKey> : IAeonicAuditBaseEntity<TKey>
    where TEntity : AeonicBaseEntity<TEntity, TKey>
    where TKey : notnull, IComparable<TKey>, IEquatable<TKey>
{


    /// <summary>
    ///     Returns true if the entity dost <b>not</b> have a value for both
    ///     <seealso cref="AeonicBaseEntity{TEntity,TKey}.DeactivatedAt" />
    ///     and
    ///     <seealso>
    ///         <cref>AeonicBaseEntity.DeletedAt</cref>
    ///     </seealso>
    /// </summary>
    /// <returns> Returns true if the entity dost <b>not</b> have a value for both DeactivatedAt and DeletedAt </returns>
    [Projectable]
    public virtual bool IsActive => this.GetEntityStatus() == AppEntityStatus.Active;

    /// <summary>
    ///     Returns true if the entity has a value for <seealso cref="AeonicBaseEntity{TEntity,TKey}.DeactivatedAt" />
    /// </summary>
    /// <returns>Returns true if the entity has a value for DeactivatedAt </returns>
    [Projectable]
    public virtual bool IsDeactivated =>
        this.GetEntityStatus() is AppEntityStatus.Deactivated or AppEntityStatus.DeactivatedAndDeleted;

    /// <summary>
    ///     Returns true if the entity has a value for <seealso cref="AeonicBaseEntity{TEntity,TKey}.DeletedAt" />
    /// </summary>
    /// <returns>Returns true if the entity has a value for DeletedAt  </returns>
    [Projectable]
    public virtual bool IsSoftDeleted =>
        this.GetEntityStatus() is AppEntityStatus.Deleted or AppEntityStatus.DeactivatedAndDeleted;


    /// <summary>
    ///     Returns the entity status of <seealso cref="AppEntityStatus.Active" />,
    ///     <seealso cref="AppEntityStatus.Deactivated" /> or <seealso cref="AppEntityStatus.Deleted" />
    /// </summary>
    /// <returns></returns>
    // ReSharper disable once MemberCanBeProtected.Global
    public virtual AppEntityStatus GetEntityStatus()
    {
        if (this.IsTransient)
        {
            return AppEntityStatus.Transient;
        }

        if ((this.DeletedAt.IsNotDefault() || this.DeletedAt.HasValue) &&
            (this.DeactivatedAt.IsNotDefault() || this.DeactivatedAt.HasValue))
        {
            return AppEntityStatus.DeactivatedAndDeleted;
        }

        if (this.DeletedAt.IsNotDefault() || this.DeletedAt.HasValue)
        {
            return AppEntityStatus.Deleted;
        }

        if (this.DeactivatedAt.IsNotDefault() || this.DeactivatedAt.HasValue)
        {
            return AppEntityStatus.Deactivated;
        }

        return AppEntityStatus.Active;
    }
}


public enum AppEntityStatus
{
    [Display(Name = "Transient")]
    Transient,

    [Display(Name = "Active")]
    Active,

    [Display(Name = "Deactivated")]
    Deactivated,

    [Display(Name = "Deleted")]
    Deleted,

    [Display(Name = "DeactivatedAndDeleted")]
    DeactivatedAndDeleted
}

Is this related to: #52 ?

Thanks for this!

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions