Exemple #1
0
        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);
        }
Exemple #2
0
 private static bool GetKeepAlive(KeepOwnerAliveMode keepOwnerAliveMode, object target)
 {
     return(keepOwnerAliveMode switch
     {
         KeepOwnerAliveMode.KeepAlive => true,
         KeepOwnerAliveMode.AutoGuess => target?.GetType().Name.Contains("<>") == true,
         _ => false
     });
Exemple #3
0
 public WeakAction(object target, Action <T> action, KeepOwnerAliveMode keepOwnerAliveMode)
     : base(target ?? action?.Target, action, keepOwnerAliveMode)
 {
 }
Exemple #4
0
 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);
        }
Exemple #6
0
 public WeakFunc(object target, Func <T> function, KeepOwnerAliveMode keepOwnerAliveMode)
     : base(target ?? function?.Target, function, keepOwnerAliveMode)
 {
 }
Exemple #7
0
 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);
 }