using System; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; namespace IRaCIS.Core.Application.Helper { public static class SafeBussinessHelper { public static async Task RunAsync(Func func, [CallerMemberName] string caller = "", string errorMsgTitle = "") { try { await func(); return true; } catch (Exception ex) { Log.Logger.Error($"【{errorMsgTitle}失败 - {caller}】: {ex.Message}"); return false; } } public static async Task<(bool Success, T? Result)> RunAsync(Func> func, [CallerMemberName] string caller = "", string errorMsgTitle = "") { try { var result = await func(); return (true, result); } catch (Exception ex) { Log.Logger.Error($"【{errorMsgTitle}失败 - {caller}】: {ex.Message}"); return (false, default); } } } }