project
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
using System.Reactive.Linq;
|
||||
|
||||
namespace TheXamlGuy.TaskbarGroup.Core
|
||||
{
|
||||
public record FileDropped();
|
||||
|
||||
public static class IObservableExtensions
|
||||
{
|
||||
public static IDisposable WeakSubscribe<TMessage>(this IObservable<TMessage> observable, IEventAggregatorInvoker invoker, Action<TMessage> actionDelegate)
|
||||
{
|
||||
var methodInfo = actionDelegate.Method;
|
||||
var weakReference = new WeakReference(actionDelegate.Target);
|
||||
IDisposable? subscription = null;
|
||||
|
||||
subscription = observable.Subscribe(item =>
|
||||
{
|
||||
if (weakReference.Target is object target)
|
||||
{
|
||||
invoker.Invoke(target, item, methodInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
subscription?.Dispose();
|
||||
}
|
||||
});
|
||||
|
||||
return subscription;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user