【发布时间】:2011-08-26 02:59:26
【问题描述】:
有没有办法在接口中指定一个已知的返回类型,但未知数量/类型的参数。
我问的原因是我使用的是 Windows Azure 表存储,每个表都有不同的分区和行键,输入值不同。
我正在创建一个ITableOperations 接口,代码将类似于:
interface ITableOperations<T>
where T : Azure.AzureTableEntity
{
// Key specification
string PartitionKey(/* ? What should go here */);
// Key specification
string RowKey(/* ? What should go here */);
}
而项目表...对于另一个表,输入参数会有所不同
public class ScheduledItem : ITableOperations<ScheduledPostEntity>
{
public string PartitionKey(Guid userGuid)
{
return userGuid.ToString();
}
public string RowKey(DateTime dateScheduled)
{
return dateScheduled.ReverseTicks();
}
}
【问题讨论】:
-
这个界面怎么用?
-
我只是想确保每个使用这个接口的类都有返回字符串的方法RowKey、PartitionKey... ITableOperations中还有其他操作,基本上是CRUD操作。
标签: c# .net design-patterns interface azure