feat: safe delegate invocation helper added

This commit is contained in:
2025-04-13 19:08:47 +03:00
parent 00f7b1aaab
commit 58eb373c79
21 changed files with 116 additions and 91 deletions

View File

@@ -0,0 +1,20 @@
using System;
namespace Syntriax.Engine.Core;
public static class DelegateHelpers
{
public static void InvokeSafe(this Delegate @delegate, params object[] args)
{
if (@delegate is null)
return;
foreach (Delegate invocation in @delegate.GetInvocationList())
try { invocation.DynamicInvoke(args); }
catch (Exception exception)
{
string methodCallRepresentation = $"{invocation.Method.DeclaringType?.FullName}.{invocation.Method.Name}({string.Join(", ", args)})";
Console.WriteLine($"Unexpected exception on invocation of method {methodCallRepresentation}:{Environment.NewLine}{exception.InnerException}");
}
}
}