Merge pull request #5775 from zyhfish/task/fix-5774

Fix #5774: remove duplicated radzen dialog delegate handlers.
This commit is contained in:
Shaun Walker
2025-11-04 11:13:30 -05:00
committed by GitHub

View File

@ -3,6 +3,7 @@
@using System.Text.RegularExpressions
@using Radzen
@using Radzen.Blazor
@using System.Reflection
@namespace Oqtane.Modules.Controls
@inherits ModuleControlBase
@ -93,6 +94,17 @@
}
await _interop.SetBackgroundColor(_editor.Element, backgroundColor);
}
var subscribers = GetEventSubscribers(DialogService, "OnOpen");
var dialogSubscibers = subscribers?.Where(s => s.Method.DeclaringType == typeof(RadzenDialog)) ?? Enumerable.Empty<Delegate>();
if (dialogSubscibers.Count() > 1)
{
//clean the event to avoid multiple RadzenDialog instances subscribing to the event
dialogSubscibers.Skip(1).ToList().ForEach(s =>
{
DialogService.OnOpen -= s as Action<string, Type, Dictionary<string, object>, DialogOptions>;
});
}
}
}
@ -212,4 +224,23 @@
{
await _interop.UpdateDialogLayout(_editor.Element);
}
private Delegate[] GetEventSubscribers(object target, string eventName)
{
var type = target.GetType();
var eventField = type.GetField(eventName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (eventField == null)
{
return null;
}
var eventDelegate = eventField.GetValue(target) as Delegate;
if (eventDelegate == null)
{
return new Delegate[0];
}
return eventDelegate.GetInvocationList();
}
}