From 42cd1608acf5bb9f99ee16fa6db7d7e7fff072c6 Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期一, 02 二月 2026 17:35:34 +0800
Subject: [PATCH] 125 防止重复注册事件的内容
---
Main/Utility/Extension.cs | 77 +++++++++++++++++++++++++++++++++++++-
1 files changed, 75 insertions(+), 2 deletions(-)
diff --git a/Main/Utility/Extension.cs b/Main/Utility/Extension.cs
index 5a2e4e8..b5d01c7 100644
--- a/Main/Utility/Extension.cs
+++ b/Main/Utility/Extension.cs
@@ -1,4 +1,77 @@
-class Extension
-{
+using System;
+using System.Collections.Generic;
+public static class Extension
+{
+ public static void RemoveCompletely<T>(this System.Action<T> action, Action<T> removeAction)
+ {
+ if (null == action)
+ {
+ return;
+ }
+
+ Delegate[] invocations = action.GetInvocationList();
+
+ for (int i = 0; i < invocations.Length; i++)
+ {
+ if (invocations[i].Equals(removeAction))
+ {
+ action -= removeAction;
+ }
+ }
+ }
+
+ public static void RemoveCompletely<T, U>(this System.Action<T, U> action, Action<T, U> removeAction)
+ {
+ if (null == action)
+ {
+ return;
+ }
+
+ Delegate[] invocations = action.GetInvocationList();
+
+ for (int i = 0; i < invocations.Length; i++)
+ {
+ if (invocations[i].Equals(removeAction))
+ {
+ action -= removeAction;
+ }
+ }
+ }
+
+ public static void RemoveCompletely(this System.Action action, Action removeAction)
+ {
+ if (null == action)
+ {
+ return;
+ }
+
+ Delegate[] invocations = action.GetInvocationList();
+
+ for (int i = 0; i < invocations.Length; i++)
+ {
+ if (invocations[i].Equals(removeAction))
+ {
+ action -= removeAction;
+ }
+ }
+ }
+
+ public static void RemoveCompletely<T, U, V>(this System.Action<T, U, V> action, Action<T, U, V> removeAction)
+ {
+ if (null == action)
+ {
+ return;
+ }
+
+ Delegate[] invocations = action.GetInvocationList();
+
+ for (int i = 0; i < invocations.Length; i++)
+ {
+ if (invocations[i].Equals(removeAction))
+ {
+ action -= removeAction;
+ }
+ }
+ }
}
\ No newline at end of file
--
Gitblit v1.8.0