コード例 #1
0
        private void RegisterCallerForStateTracking(string caller)
        {
            var instanceType = TypeDescriptor.GetReflectionType(this);
            var propertyInfo = caller != null?instanceType.GetProperty(caller) : null;

            var dateTime   = DateTime.Now;
            var infoString = $"{propertyInfo?.ReflectedType.Name}.{propertyInfo?.Name}";
            var key        = $"{dateTime.ToLongTimeString()}.{dateTime.Millisecond} {(infoString.Length > 1 ? infoString : $"{dateTime.ToLongTimeString()}.{dateTime.Millisecond} {GetType().ToString()}")}";

            if (propertyInfo is null)
            {
                // in case of Collection.Add the constructor of added class should fire NotifyPropertyChanged
                _mementoService.RegisterObject(this);
                _mementoHashtable.Add(key, this);
                return;
            }

            var propertyValueType = propertyInfo.GetValue(this);

            if (propertyValueType is INotifyCollectionChanged notifyCollectionChanged)
            {
                // double registration will be checked by MementoService it self
                _mementoService.RegisterCollection(notifyCollectionChanged);
                key += COLLECTION_INDICATOR;
            }
            else if (propertyValueType is INotifyPropertyChanged notifyPropertyChanged)
            {
                // double registration will be checked by MementoService it self
                _mementoService.RegisterObject(notifyPropertyChanged);
                key += OBJECT_INDICATOR;
            }

            _mementoHashtable.Add(key, propertyValueType);
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PersonViewModel"/> class.
        /// </summary>
        /// <param name="person">The person.</param>
        public PersonViewModel(Person person, IMementoService mementoService)
        {
            _mementoService = mementoService;

            Person = person ?? new Person();

            Undo = new Command(() => _mementoService.Undo(), () => _mementoService.CanUndo);
            Redo = new Command(() => _mementoService.Redo(), () => _mementoService.CanRedo);

            GenerateData = new Command<object, object>(OnGenerateDataExecute, OnGenerateDataCanExecute);
            ToggleCustomError = new Command<object>(OnToggleCustomErrorExecute);

            _mementoService.RegisterObject(this);
        }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PersonViewModel"/> class.
        /// </summary>
        /// <param name="person">The person.</param>
        public PersonViewModel(Person person, IMementoService mementoService)
        {
            _mementoService = mementoService;

            Person = person ?? new Person();

            Undo = new Command(() => _mementoService.Undo(), () => _mementoService.CanUndo);
            Redo = new Command(() => _mementoService.Redo(), () => _mementoService.CanRedo);

            GenerateData      = new Command <object, object>(OnGenerateDataExecute, OnGenerateDataCanExecute);
            ToggleCustomError = new Command <object>(OnToggleCustomErrorExecute);

            _mementoService.RegisterObject(this);
        }