Skip to content

Commit

Permalink
Merge pull request #30 from techno-dwarf-works/feature/refactoring
Browse files Browse the repository at this point in the history
Version 0.0.27
  • Loading branch information
uurha committed Jul 30, 2024
1 parent 363b227 commit e62e26a
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 18 deletions.
85 changes: 68 additions & 17 deletions Runtime/Extensions/ActionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,303 +9,354 @@ public static class ActionExtensions

#region SafeInvoke`16

public static void SafeInvoke(this Action self, bool logException = DefaultLogException)
public static bool TryInvoke(this Action self, bool logException = DefaultLogException)
{
try
{
self.Invoke();
return true;
}
catch (Exception exception)
{
if (logException)
{
DebugUtility.LogException(exception);
}

return false;
}
}

public static void SafeInvoke<T>(this Action<T> self, T obj, bool logException = DefaultLogException)
public static bool TryInvoke<T>(this Action<T> self, T obj, bool logException = DefaultLogException)
{
try
{
self.Invoke(obj);
return true;
}
catch (Exception exception)
{
if (logException)
{
DebugUtility.LogException(exception);
}

return false;
}
}

public static void SafeInvoke<T1, T2>(
public static bool TryInvoke<T1, T2>(
this Action<T1, T2> self,
T1 arg1, T2 arg2,
bool logException = DefaultLogException)
{
try
{
self.Invoke(arg1, arg2);
return true;
}
catch (Exception exception)
{
if (logException)
{
DebugUtility.LogException(exception);
}

return false;
}
}

public static void SafeInvoke<T1, T2, T3>(
public static bool TryInvoke<T1, T2, T3>(
this Action<T1, T2, T3> self,
T1 arg1, T2 arg2, T3 arg3,
bool logException = DefaultLogException)
{
try
{
self.Invoke(arg1, arg2, arg3);
return true;
}
catch (Exception exception)
{
if (logException)
{
DebugUtility.LogException(exception);
}

return false;
}
}

public static void SafeInvoke<T1, T2, T3, T4>(
public static bool TryInvoke<T1, T2, T3, T4>(
this Action<T1, T2, T3, T4> self,
T1 arg1, T2 arg2, T3 arg3, T4 arg4,
bool logException = DefaultLogException)
{
try
{
self.Invoke(arg1, arg2, arg3, arg4);
return true;
}
catch (Exception exception)
{
if (logException)
{
DebugUtility.LogException(exception);
}

return false;
}
}

public static void SafeInvoke<T1, T2, T3, T4, T5>(
public static bool TryInvoke<T1, T2, T3, T4, T5>(
this Action<T1, T2, T3, T4, T5> self,
T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5,
bool logException = DefaultLogException)
{
try
{
self.Invoke(arg1, arg2, arg3, arg4, arg5);
return true;
}
catch (Exception exception)
{
if (logException)
{
DebugUtility.LogException(exception);
}

return false;
}
}

public static void SafeInvoke<T1, T2, T3, T4, T5, T6>(
public static bool TryInvoke<T1, T2, T3, T4, T5, T6>(
this Action<T1, T2, T3, T4, T5, T6> self,
T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6,
bool logException = DefaultLogException)
{
try
{
self.Invoke(arg1, arg2, arg3, arg4, arg5, arg6);
return true;
}
catch (Exception exception)
{
if (logException)
{
DebugUtility.LogException(exception);
}

return false;
}
}

public static void SafeInvoke<T1, T2, T3, T4, T5, T6, T7>(
public static bool TryInvoke<T1, T2, T3, T4, T5, T6, T7>(
this Action<T1, T2, T3, T4, T5, T6, T7> self,
T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7,
bool logException = DefaultLogException)
{
try
{
self.Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
return true;
}
catch (Exception exception)
{
if (logException)
{
DebugUtility.LogException(exception);
}

return false;
}
}

public static void SafeInvoke<T1, T2, T3, T4, T5, T6, T7, T8>(
public static bool TryInvoke<T1, T2, T3, T4, T5, T6, T7, T8>(
this Action<T1, T2, T3, T4, T5, T6, T7, T8> self,
T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8,
bool logException = DefaultLogException)
{
try
{
self.Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
return true;
}
catch (Exception exception)
{
if (logException)
{
DebugUtility.LogException(exception);
}

return false;
}
}

public static void SafeInvoke<T1, T2, T3, T4, T5, T6, T7, T8, T9>(
public static bool TryInvoke<T1, T2, T3, T4, T5, T6, T7, T8, T9>(
this Action<T1, T2, T3, T4, T5, T6, T7, T8, T9> self,
T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9,
bool logException = DefaultLogException)
{
try
{
self.Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
return true;
}
catch (Exception exception)
{
if (logException)
{
DebugUtility.LogException(exception);
}

return false;
}
}

public static void SafeInvoke<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(
public static bool TryInvoke<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(
this Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> self,
T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10,
bool logException = DefaultLogException)
{
try
{
self.Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);
return true;
}
catch (Exception exception)
{
if (logException)
{
DebugUtility.LogException(exception);
}

return false;
}
}

public static void SafeInvoke<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(
public static bool TryInvoke<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(
this Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> 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)
{
try
{
self.Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11);
return true;
}
catch (Exception exception)
{
if (logException)
{
DebugUtility.LogException(exception);
}

return false;
}
}

public static void SafeInvoke<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(
public static bool TryInvoke<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(
this Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> 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)
{
try
{
self.Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12);
return true;
}
catch (Exception exception)
{
if (logException)
{
DebugUtility.LogException(exception);
}

return false;
}
}

public static void SafeInvoke<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(
public static bool TryInvoke<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(
this Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> 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)
{
try
{
self.Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13);
return true;
}
catch (Exception exception)
{
if (logException)
{
DebugUtility.LogException(exception);
}

return false;
}
}

public static void SafeInvoke<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(
public static bool TryInvoke<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(
this Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> 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)
{
try
{
self.Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14);
return true;
}
catch (Exception exception)
{
if (logException)
{
DebugUtility.LogException(exception);
}

return false;
}
}

public static void SafeInvoke<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(
public static bool TryInvoke<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(
this Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> 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)
{
try
{
self.Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15);
return true;
}
catch (Exception exception)
{
if (logException)
{
DebugUtility.LogException(exception);
}

return false;
}
}

public static void SafeInvoke<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>(
public static bool TryInvoke<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>(
this Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> 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)
{
try
{
self.Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16);
return true;
}
catch (Exception exception)
{
if (logException)
{
DebugUtility.LogException(exception);
}

return false;
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.tdw.better.commons",
"displayName": "Better Commons",
"version": "0.0.26",
"version": "0.0.27",
"unity": "2021.3",
"description": " ",
"dependencies": {
Expand Down

0 comments on commit e62e26a

Please sign in to comment.