我目前有这个通用方法:
public virtual T Get(Expression<Func<T, bool>> predicate)
{
return this.Query.Where(predicate).FirstOrDefault();
}
下面是我如何调用该方法的示例:
ST = testTable.Get( u => u.PartitionKey == pKey & u.RowKey == rKey );
我真的不太了解泛型,我需要做的是有一个方法将 partitionKey 和 rowKey 作为参数并执行 Get。像这样:
ST = testTable.Get(pkey,rkey);
有没有人知道我该怎么做?
最佳答案
您需要创建一个接受这些参数的函数,并使用使用这些参数的 lambda 表达式调用第一个函数。
public T Get(pkey,rkey)
{
return Get(u => u.PartitionKey == pKey & u.RowKey == rKey);
}
如果 T
不限于继承具有这些属性的类型,则您需要创建一个扩展方法,以使用具有这些属性的类型参数扩展您的类。
关于c# - 泛型方法和谓词的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6733864/