示例#1
0
        /// <summary>
        /// Notifies all subscribed observers with the value.
        /// </summary>
        /// <param name="value">The value to send to all subscribed observers.</param>
        public void OnNext(T value)
        {
            IObserver <T>[] observers = null;
            lock (_gate)
            {
                ThrowIfDisposed();
                if (_observers != null)
                {
                    observers = _observers.ToArray();
                }
            }

            if (observers != null)
            {
                foreach (var observer in observers)
                {
                    observer.OnNext(value);
                }
            }
        }
示例#2
0
        private void EnsureCommandCreated()
        {
            if (!_commandCreated)
            {
                _commandCreated = true;
                _addInCommand   = CreateCommand(_codon);
                if (_canExecuteChangedHandlersToRegisterOnCommand != null)
                {
                    var handlers = _canExecuteChangedHandlersToRegisterOnCommand.ToArray();
                    _canExecuteChangedHandlersToRegisterOnCommand = null;

                    foreach (var handler in handlers)
                    {
                        if (_addInCommand != null)
                        {
                            _addInCommand.CanExecuteChanged += handler;
                        }
                        // Creating the command potentially changes the CanExecute state, so we should raise the event handlers once:
                        handler(this, EventArgs.Empty);
                    }
                }
            }
        }