我想创建一个通用函数,我可以指定要调用的方法&它应该尝试在失败之前获取结果的次数。c#或vb通用函数重试代码块n次数
喜欢的东西:
//3 stands for maximum number of times GetCustomerbyId should be called if it fails on first attempt.
var result = RetryCall(GetCustomerbyId(id),3);
其次,返回类型应该会自动根据功能被调用调整。
例如我应该可以从以下两个函数中得到结果,一个返回字符串&其他Customer实体。
public static string GetCustomerFullNamebyId(int id){
return dataContext.Customers.Where(c => c.Id.Equals(id)).SingleOrDefault().FullName;
}
public static Customer GetCustomerbyId(int id){
return dataContext.Customers.Find(id);
}
这可能吗?
调用'GetCustomerbyId(id)'时失败的样子是什么?例外?一个'null'字符串?一个'null'对象? – Enigmativity