I am trying to create a generic interface to be applied to class objects that have to be auditable: i.e. have the ID of the user that created, modified, or deleted the object, and the DateTime of the event.
The problem is that an object that has not been modified or deleted must have a null value for the corresponding Id and Date values.
My current definition is:
public interface IAuditedEntity<UserIdType>
{
UserIdType CreatedBy { get; }
DateTime DateCreated { get; }
UserIdType? ModifiedBy { get; }
DateTime? DateModified { get; }
UserIdType? DeletedBy { get; }
DateTime? DateDeleted { get; }
}
public class AuditedClass : IAuditedEntity<int>{
public int Id { get; protected set; }
public int CreatedBy { get; protected set; }
public DateTime DateCreated { get; set; }
public int? ModifiedBy { get; protected set; }
public DateTime? DateModified {get; protected set; }
public int? DeletedBy { get; protected set; }
public DateTime? DateDeleted { get; protected set; }
}
In Visual Studio 2022 (latest release), I get an error that the interface is not completely implemented.
I need the generic because in this module the user’s Id is an int, but in other modules it could be a string or GUID.
Victor Jackson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.