【发布时间】:2016-07-27 10:26:01
【问题描述】:
我正在尝试创建一个通用函数,我可以在其中指定要调用的方法以及在失败之前它应该尝试获取结果的次数。
类似:
//3 stands for maximum number of times GetCustomerbyId should be called if it fails on first attempt.
var result = RetryCall(GetCustomerbyId(id),3);
其次,返回类型应该根据它调用的函数自动调整。
例如,我应该能够从以下两个函数中获取结果,一个返回字符串和其他客户实体。
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对象?
标签: c# .net dynamic reflection