You can try to have a very common interface. For instance:
interface ITableOperations<T, P, R> where T : Azure.AzureTableEntity { string PartitionKey(P partitionKey); string RowKey(R rowKey); }
Then your implementation could be:
public class ScheduledItem : ITableOperations<ScheduledPostEntity, Guid, DateTime> { public string PartitionKey(Guid userGuid) { return userGuid.ToString(); } public string RowKey(DateTime dateScheduled) { return dateScheduled.ReverseTicks(); } }
EDIT:
Looking at some of your comments, since I originally wrote this answer, you could come to it from a different angle. PartitionKey and RowKey will not change on your object after its creation, so I would almost exclude these specific functions from this class and move it to the class constructors that inherit from AzureTableEntity . eg.
public class ScheduledPostEntity : Azure.AzureTableEntity { private Guid _userGuid; private DateTime _dateScheduled; public ScheduledPostEntity() {
This has the advantage that whenever you create these objects, you know the minimum requirements for saving the object. It also prevents you from messing with things that will change your PCs and RCs.
source share