mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-02-11 10:34:35 +01:00
chore: convert Dalamud to file-scoped namespaces
This commit is contained in:
parent
b093323acc
commit
987ff8dc8f
368 changed files with 55081 additions and 55450 deletions
|
|
@ -6,93 +6,92 @@ using Serilog;
|
|||
|
||||
using static Dalamud.Game.Framework;
|
||||
|
||||
namespace Dalamud.Utility
|
||||
namespace Dalamud.Utility;
|
||||
|
||||
/// <summary>
|
||||
/// Extensions for Events.
|
||||
/// </summary>
|
||||
internal static class EventHandlerExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Extensions for Events.
|
||||
/// Replacement for Invoke() on EventHandlers to catch exceptions that stop event propagation in case
|
||||
/// of a thrown Exception inside of an invocation.
|
||||
/// </summary>
|
||||
internal static class EventHandlerExtensions
|
||||
/// <param name="eh">The EventHandler in question.</param>
|
||||
/// <param name="sender">Default sender for Invoke equivalent.</param>
|
||||
/// <param name="e">Default EventArgs for Invoke equivalent.</param>
|
||||
public static void InvokeSafely(this EventHandler eh, object sender, EventArgs e)
|
||||
{
|
||||
/// <summary>
|
||||
/// Replacement for Invoke() on EventHandlers to catch exceptions that stop event propagation in case
|
||||
/// of a thrown Exception inside of an invocation.
|
||||
/// </summary>
|
||||
/// <param name="eh">The EventHandler in question.</param>
|
||||
/// <param name="sender">Default sender for Invoke equivalent.</param>
|
||||
/// <param name="e">Default EventArgs for Invoke equivalent.</param>
|
||||
public static void InvokeSafely(this EventHandler eh, object sender, EventArgs e)
|
||||
{
|
||||
if (eh == null)
|
||||
return;
|
||||
if (eh == null)
|
||||
return;
|
||||
|
||||
foreach (var handler in eh.GetInvocationList().Cast<EventHandler>())
|
||||
{
|
||||
HandleInvoke(() => handler(sender, e));
|
||||
}
|
||||
foreach (var handler in eh.GetInvocationList().Cast<EventHandler>())
|
||||
{
|
||||
HandleInvoke(() => handler(sender, e));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replacement for Invoke() on generic EventHandlers to catch exceptions that stop event propagation in case
|
||||
/// of a thrown Exception inside of an invocation.
|
||||
/// </summary>
|
||||
/// <param name="eh">The EventHandler in question.</param>
|
||||
/// <param name="sender">Default sender for Invoke equivalent.</param>
|
||||
/// <param name="e">Default EventArgs for Invoke equivalent.</param>
|
||||
/// <typeparam name="T">Type of EventArgs.</typeparam>
|
||||
public static void InvokeSafely<T>(this EventHandler<T> eh, object sender, T e)
|
||||
/// <summary>
|
||||
/// Replacement for Invoke() on generic EventHandlers to catch exceptions that stop event propagation in case
|
||||
/// of a thrown Exception inside of an invocation.
|
||||
/// </summary>
|
||||
/// <param name="eh">The EventHandler in question.</param>
|
||||
/// <param name="sender">Default sender for Invoke equivalent.</param>
|
||||
/// <param name="e">Default EventArgs for Invoke equivalent.</param>
|
||||
/// <typeparam name="T">Type of EventArgs.</typeparam>
|
||||
public static void InvokeSafely<T>(this EventHandler<T> eh, object sender, T e)
|
||||
{
|
||||
if (eh == null)
|
||||
return;
|
||||
|
||||
foreach (var handler in eh.GetInvocationList().Cast<EventHandler<T>>())
|
||||
{
|
||||
if (eh == null)
|
||||
return;
|
||||
|
||||
foreach (var handler in eh.GetInvocationList().Cast<EventHandler<T>>())
|
||||
{
|
||||
HandleInvoke(() => handler(sender, e));
|
||||
}
|
||||
HandleInvoke(() => handler(sender, e));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replacement for Invoke() on event Actions to catch exceptions that stop event propagation in case
|
||||
/// of a thrown Exception inside of an invocation.
|
||||
/// </summary>
|
||||
/// <param name="act">The Action in question.</param>
|
||||
public static void InvokeSafely(this Action act)
|
||||
/// <summary>
|
||||
/// Replacement for Invoke() on event Actions to catch exceptions that stop event propagation in case
|
||||
/// of a thrown Exception inside of an invocation.
|
||||
/// </summary>
|
||||
/// <param name="act">The Action in question.</param>
|
||||
public static void InvokeSafely(this Action act)
|
||||
{
|
||||
if (act == null)
|
||||
return;
|
||||
|
||||
foreach (var action in act.GetInvocationList().Cast<Action>())
|
||||
{
|
||||
if (act == null)
|
||||
return;
|
||||
|
||||
foreach (var action in act.GetInvocationList().Cast<Action>())
|
||||
{
|
||||
HandleInvoke(action);
|
||||
}
|
||||
HandleInvoke(action);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replacement for Invoke() on OnUpdateDelegate to catch exceptions that stop event propagation in case
|
||||
/// of a thrown Exception inside of an invocation.
|
||||
/// </summary>
|
||||
/// <param name="updateDelegate">The OnUpdateDelegate in question.</param>
|
||||
/// <param name="framework">Framework to be passed on to OnUpdateDelegate.</param>
|
||||
public static void InvokeSafely(this OnUpdateDelegate updateDelegate, Framework framework)
|
||||
/// <summary>
|
||||
/// Replacement for Invoke() on OnUpdateDelegate to catch exceptions that stop event propagation in case
|
||||
/// of a thrown Exception inside of an invocation.
|
||||
/// </summary>
|
||||
/// <param name="updateDelegate">The OnUpdateDelegate in question.</param>
|
||||
/// <param name="framework">Framework to be passed on to OnUpdateDelegate.</param>
|
||||
public static void InvokeSafely(this OnUpdateDelegate updateDelegate, Framework framework)
|
||||
{
|
||||
if (updateDelegate == null)
|
||||
return;
|
||||
|
||||
foreach (var action in updateDelegate.GetInvocationList().Cast<OnUpdateDelegate>())
|
||||
{
|
||||
if (updateDelegate == null)
|
||||
return;
|
||||
|
||||
foreach (var action in updateDelegate.GetInvocationList().Cast<OnUpdateDelegate>())
|
||||
{
|
||||
HandleInvoke(() => action(framework));
|
||||
}
|
||||
HandleInvoke(() => action(framework));
|
||||
}
|
||||
}
|
||||
|
||||
private static void HandleInvoke(Action act)
|
||||
private static void HandleInvoke(Action act)
|
||||
{
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
act();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, "Exception during raise of {handler}", act.Method);
|
||||
}
|
||||
act();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, "Exception during raise of {handler}", act.Method);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue