The following code from my team mate works:
public T Get<T, V>(V repo, string pk, string rk)
where T : Microsoft.WindowsAzure.StorageClient.TableServiceEntity
where V : IAzureTable<T>
{
try
{
var item = repo.GetPkRk(pk, rk);
if (item == null) throw new Exception(); return (T)item;
}
catch (Exception ex)
{
_ex.Errors.Add("", typeof(T).Name + rk + " does not exist");
throw _ex;
}
}
Calling code:
var account = base.Get<Account, IAzureTable<Account>>(_accountRepository, pk, rk);
Can it be simplified. The only type variable here is “Account” and I am wondering if the T and V types could be combined into one as V depends only on T.
Yes
then
you could possibly even get away with
if the compiler can infer the parameter type from
_accountRepository.