I read that multiple inheritance doesn't exist in c# but can be mocked by using interfaces
I am trying to do something similar and it doesn't seem to be working. Wondering what I might be doing wrong. I've defined my concrete class to inherit from:
public class AppSettings {
public string CosmosDbPrimaryKey {get; set;}
}
and then my "super" class that inherits from AppSettings
directly and implements ITableEntity
. This class should ultimately act as if it inherited from both AppSettings and TableEntity.
public class AppSettingsRow: AppSettings, ITableEntity
{
private readonly TableEntity _tableEntity;
public AppSettingsRow()
{
_tableEntity = new TableEntity();
}
public string PartitionKey { get; set; }
public string RowKey { get; set; }
public DateTimeOffset Timestamp { get; set; }
public string ETag { get; set; }
public void ReadEntity(IDictionary<string, EntityProperty> properties, OperationContext operationContext)
{
_tableEntity.ReadEntity(properties, operationContext);
}
public IDictionary<string, EntityProperty> WriteEntity(OperationContext operationContext)
{
return _tableEntity.WriteEntity(operationContext);
}
}
The issue is that when I actually use the class and list rows from a table the AppSettings field show up as null.
If I do the opposite and inherit directly from TableEntity and implement AppSettings it works just fine however this is not desirable for me. AppSettings is likely to change with time and I don't want to have to maintain the two separate models every time a change happens.
What am I doing wrong?