asp.net – 如何使用返回类型的System.Action?
发布时间:2020-12-16 03:39:06 所属栏目:asp.Net 来源:网络整理
导读:在BLL课程中,我写道: Private ListT GetData(string a,string b){ TryAction(()={ //Call BLL Method to retrieve the list of BO. return BLLInstance.GetAllList(a,b); });} 在BLL基类中,我有一个方法: protected void TryAction(Action action){ try {
在BLL课程中,我写道:
Private List<T> GetData(string a,string b) { TryAction(()=>{ //Call BLL Method to retrieve the list of BO. return BLLInstance.GetAllList(a,b); }); } 在BLL基类中,我有一个方法: protected void TryAction(Action action) { try { action(); } catch(Exception e) { // write exception to output (Response.Write(str)) } } 如何将TryAction()方法与泛型返回类型一起使用? 解决方法
您需要使用Func来表示将返回值的方法.
以下是一个例子 private List<int> GetData(string a,string b) { return TryAction(() => { //Call BLL Method to retrieve the list of BO. return BLLInstance.GetAllList(a,b); }); } protected TResult TryAction<TResult>(Func<TResult> action) { try { return action(); } catch (Exception e) { throw; // write exception to output (Response.Write(str)) } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ASP.NET MVC5+EF6+EasyUI 后台管理系统(65)-MVC WebApi 用
- oauth-2.0 – 在MVC6应用程序中的OAuth令牌到期
- asp.net-mvc-3 – 在编辑模板中,如何将javascript放在head部
- asp.net-mvc – 关闭剃刀中的HTML编码
- asp.net分页控件AspNetPager的样式美化
- asp.net-mvc – 可以更改Html.DropDownListFor生成的html名
- asp.net-ajax – 如何在ASP.NET AJAX中实现文件下载
- MvcBuildViews真实与实体框架在ASP.NET MVC 2
- asp.net-mvc-3 – 如何在MVC3应用程序的页脚上显示版本号
- asp.net – 从IIS6向IIS7.5移动AJAX调用,在System.Web.Hand
推荐文章
站长推荐
热点阅读