public WeakBase(object owner, T data, KeepOwnerAliveMode keepOwnerAliveMode) { Ensure.IsNotNull(data, nameof(data)); KeepOwnerAlive = GetKeepAlive(keepOwnerAliveMode, owner); if (owner != null) { _ownerReference = new WeakReference(owner); if (KeepOwnerAlive) { _owner = owner; } _data = data; } if (KeepOwnerAlive) { _data = data; } _dataReference = new WeakReference <T>(data); }
private static bool GetKeepAlive(KeepOwnerAliveMode keepOwnerAliveMode, object target) { return(keepOwnerAliveMode switch { KeepOwnerAliveMode.KeepAlive => true, KeepOwnerAliveMode.AutoGuess => target?.GetType().Name.Contains("<>") == true, _ => false });
public WeakAction(object target, Action <T> action, KeepOwnerAliveMode keepOwnerAliveMode) : base(target ?? action?.Target, action, keepOwnerAliveMode) { }
public WeakAction(Action <T> action, KeepOwnerAliveMode keepOwnerAliveMode) : this(action?.Target, action, keepOwnerAliveMode) { }
public IDisposable Register <TMessage>(object receiver, Action <TMessage> action, KeepOwnerAliveMode keepOwnerAliveMode) { var actions = GetRegistrationsForMessageType <TMessage>(); var registration = new MessengerRegistration <TMessage>(this, receiver, action, keepOwnerAliveMode); actions.Add(registration); return(registration); }
public WeakFunc(object target, Func <T> function, KeepOwnerAliveMode keepOwnerAliveMode) : base(target ?? function?.Target, function, keepOwnerAliveMode) { }
public WeakFunc(Func <T> function, KeepOwnerAliveMode keepOwnerAliveMode) : this(function?.Target, function, keepOwnerAliveMode) { }
public MessengerRegistration(MessengerImpl messenger, object receiver, Action <TMessage> action, KeepOwnerAliveMode keepOwnerAliveMode) { _messenger = messenger; _weakAction = new WeakAction <TMessage>(receiver, action, keepOwnerAliveMode); }