I'm a little lost on casting generic types and wondering if anyone could please point out what I'm missing.
I have this abstract class definition:
public abstract class BaseEntityTypeConfiguration<TEntity> : IEntityTypeConfiguration<TEntity>
where TEntity : class
{
public void Configure(EntityTypeBuilder<TEntity> builder)
{
ConfigureEntity(builder);
var audited = builder as EntityTypeBuilder<IAuditedEntity>;
audited?.ConfigureAudited();
var timestamped = builder as EntityTypeBuilder<ITimestampEnabled>;
timestamped?.ConfigureTimestamp();
var softDelete = builder as EntityTypeBuilder<ISoftDelete>;
softDelete?.ConfigureSoftDelete();
}
public abstract void ConfigureEntity(EntityTypeBuilder<TEntity> builder);
}
In my project this is invoked where TEntity is a Customer class which Implements IAuditedEntity and ITimestampEnabled.
How do I cast the EntityTypeBuilder<TEntity> builder parameter to EntityTypeBuilder<IAuditedEntity>, etc?