예제 #1
0
        /// <summary>
        /// Adds a runtime observable property.
        /// </summary>
        /// <param name="propertyName">Property name.</param>
        private ReactiveProperty <T> AddProperty <T>(Type propertyType, ReactiveProperty <T> property)
        {
            if (_propertyValues.ContainsKey(property.Name))
            {
                throw new InvalidOperationException($"{property.Name} already exists.");
            }

            property.Subscribe(_ => Changed(property.Name));
            RuntimeProperties.Add(property);
            Set(property, property.Name);
            return(property);
        }
예제 #2
0
        /// <summary>
        /// Constructor to create a wrapper for a view model that doesn't inherit from BaseVM.
        /// </summary>
        /// <param name="vm">View model instance.</param>
        internal BaseVM(INotifyPropertyChanged vm) : base()
        {
            _vmInstance         = vm;
            vm.PropertyChanged += OnPropertyChanged;
            _changedProperties  = _propertyDictionaries.Dequeue();

            if (vm is IReactiveProperties && (vm as IReactiveProperties).RuntimeProperties != null)
            {
                var runtimeProperties = (vm as IReactiveProperties).RuntimeProperties.Where(prop => !string.IsNullOrWhiteSpace(prop.Name)).ToList();
                runtimeProperties.ForEach(prop =>
                {
                    prop.PropertyChanged += OnPropertyChanged;
                    RuntimeProperties.Add(prop);
                    Set(prop, prop.Name);
                });
                Disposed += (sender, e) => runtimeProperties.ForEach(prop => prop.PropertyChanged -= OnPropertyChanged);
                IgnoredProperties.Add(nameof(IReactiveProperties.RuntimeProperties));
            }

            if (vm is IPushUpdates)
            {
                (vm as IPushUpdates).RequestPushUpdates += (sender, e) => RequestPushUpdates?.Invoke(this, e);
            }

            if (vm is IDisposable)
            {
                Disposed += (sender, e) =>
                {
                    vm.PropertyChanged -= OnPropertyChanged;
                    (vm as IDisposable).Dispose();
                }
            }
            ;

            if (vm is IBaseVMAccessor)
            {
                (vm as IBaseVMAccessor).OnInitialized?.Invoke(this);
            }
        }