From d5cc5f3c0ef51ac562fddf1c35904012616d61bc Mon Sep 17 00:00:00 2001 From: uurha Date: Tue, 30 Jul 2024 21:30:37 +0000 Subject: [PATCH] Merge pull request #31 from techno-dwarf-works/feature/refactoring Version 0.0.28 --- Runtime/Extensions/FuncExtensions.cs | 168 ++++++++++++++++----------- package.json | 2 +- 2 files changed, 102 insertions(+), 68 deletions(-) diff --git a/Runtime/Extensions/FuncExtensions.cs b/Runtime/Extensions/FuncExtensions.cs index 2f17437..4d9c8ab 100644 --- a/Runtime/Extensions/FuncExtensions.cs +++ b/Runtime/Extensions/FuncExtensions.cs @@ -9,11 +9,12 @@ public static class FuncExtensions #region SafeInvoke`16 - public static TResult SafeInvoke(this Func self, bool logException = DefaultLogException) + public static bool TryInvoke(this Func self, out TResult result, bool logException = DefaultLogException) { try { - return self.Invoke(); + result = self.Invoke(); + return true; } catch (Exception exception) { @@ -22,18 +23,20 @@ public static TResult SafeInvoke(this Func self, bool logExcep DebugUtility.LogException(exception); } - return default; + result = default; + return false; } } - public static TResult SafeInvoke( + public static bool TryInvoke( this Func self, T arg, - bool logException = DefaultLogException) + out TResult result, bool logException = DefaultLogException) { try { - return self.Invoke(arg); + result = self.Invoke(arg); + return true; } catch (Exception exception) { @@ -42,18 +45,20 @@ public static TResult SafeInvoke( DebugUtility.LogException(exception); } - return default; + result = default; + return false; } } - public static TResult SafeInvoke( + public static bool TryInvoke( this Func self, T1 arg1, T2 arg2, - bool logException = DefaultLogException) + out TResult result, bool logException = DefaultLogException) { try { - return self.Invoke(arg1, arg2); + result = self.Invoke(arg1, arg2); + return true; } catch (Exception exception) { @@ -62,18 +67,20 @@ public static TResult SafeInvoke( DebugUtility.LogException(exception); } - return default; + result = default; + return false; } } - public static TResult SafeInvoke( + public static bool TryInvoke( this Func self, T1 arg1, T2 arg2, T3 arg3, - bool logException = DefaultLogException) + out TResult result, bool logException = DefaultLogException) { try { - return self.Invoke(arg1, arg2, arg3); + result = self.Invoke(arg1, arg2, arg3); + return true; } catch (Exception exception) { @@ -82,18 +89,20 @@ public static TResult SafeInvoke( DebugUtility.LogException(exception); } - return default; + result = default; + return false; } } - public static TResult SafeInvoke( + public static bool TryInvoke( this Func self, T1 arg1, T2 arg2, T3 arg3, T4 arg4, - bool logException = DefaultLogException) + out TResult result, bool logException = DefaultLogException) { try { - return self.Invoke(arg1, arg2, arg3, arg4); + result = self.Invoke(arg1, arg2, arg3, arg4); + return true; } catch (Exception exception) { @@ -102,18 +111,20 @@ public static TResult SafeInvoke( DebugUtility.LogException(exception); } - return default; + result = default; + return false; } } - public static TResult SafeInvoke( + public static bool TryInvoke( this Func self, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, - bool logException = DefaultLogException) + out TResult result, bool logException = DefaultLogException) { try { - return self.Invoke(arg1, arg2, arg3, arg4, arg5); + result = self.Invoke(arg1, arg2, arg3, arg4, arg5); + return true; } catch (Exception exception) { @@ -122,18 +133,20 @@ public static TResult SafeInvoke( DebugUtility.LogException(exception); } - return default; + result = default; + return false; } } - public static TResult SafeInvoke( + public static bool TryInvoke( this Func self, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, - bool logException = DefaultLogException) + out TResult result, bool logException = DefaultLogException) { try { - return self.Invoke(arg1, arg2, arg3, arg4, arg5, arg6); + result = self.Invoke(arg1, arg2, arg3, arg4, arg5, arg6); + return true; } catch (Exception exception) { @@ -142,18 +155,20 @@ public static TResult SafeInvoke( DebugUtility.LogException(exception); } - return default; + result = default; + return false; } } - public static TResult SafeInvoke( + public static bool TryInvoke( this Func self, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, - bool logException = DefaultLogException) + out TResult result, bool logException = DefaultLogException) { try { - return self.Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7); + result = self.Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7); + return true; } catch (Exception exception) { @@ -162,18 +177,20 @@ public static TResult SafeInvoke( DebugUtility.LogException(exception); } - return default; + result = default; + return false; } } - public static TResult SafeInvoke( + public static bool TryInvoke( this Func self, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, - bool logException = DefaultLogException) + out TResult result, bool logException = DefaultLogException) { try { - return self.Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); + result = self.Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); + return true; } catch (Exception exception) { @@ -182,18 +199,20 @@ public static TResult SafeInvoke( DebugUtility.LogException(exception); } - return default; + result = default; + return false; } } - public static TResult SafeInvoke( + public static bool TryInvoke( this Func self, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, - bool logException = DefaultLogException) + out TResult result, bool logException = DefaultLogException) { try { - return self.Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); + result = self.Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); + return true; } catch (Exception exception) { @@ -202,18 +221,20 @@ public static TResult SafeInvoke( DebugUtility.LogException(exception); } - return default; + result = default; + return false; } } - public static TResult SafeInvoke( + public static bool TryInvoke( this Func self, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, - bool logException = DefaultLogException) + out TResult result, bool logException = DefaultLogException) { try { - return self.Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); + result = self.Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); + return true; } catch (Exception exception) { @@ -222,18 +243,20 @@ public static TResult SafeInvoke( + public static bool TryInvoke( this Func self, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, - bool logException = DefaultLogException) + out TResult result, bool logException = DefaultLogException) { try { - return self.Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11); + result = self.Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11); + return true; } catch (Exception exception) { @@ -242,18 +265,20 @@ public static TResult SafeInvoke( + public static bool TryInvoke( this Func self, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, - bool logException = DefaultLogException) + out TResult result, bool logException = DefaultLogException) { try { - return self.Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12); + result = self.Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12); + return true; } catch (Exception exception) { @@ -262,18 +287,20 @@ public static TResult SafeInvoke( + public static bool TryInvoke( this Func self, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, - bool logException = DefaultLogException) + out TResult result, bool logException = DefaultLogException) { try { - return self.Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13); + result = self.Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13); + return true; } catch (Exception exception) { @@ -282,18 +309,20 @@ public static TResult SafeInvoke( + public static bool TryInvoke( this Func self, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, - bool logException = DefaultLogException) + out TResult result, bool logException = DefaultLogException) { try { - return self.Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14); + result = self.Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14); + return true; } catch (Exception exception) { @@ -302,18 +331,20 @@ public static TResult SafeInvoke( + public static bool TryInvoke( this Func self, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, - bool logException = DefaultLogException) + out TResult result, bool logException = DefaultLogException) { try { - return self.Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15); + result = self.Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15); + return true; } catch (Exception exception) { @@ -322,18 +353,20 @@ public static TResult SafeInvoke( + public static bool TryInvoke( this Func self, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16, - bool logException = DefaultLogException) + out TResult result, bool logException = DefaultLogException) { try { - return self.Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16); + result = self.Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16); + return true; } catch (Exception exception) { @@ -342,7 +375,8 @@ public static TResult SafeInvoke