예제 #1
0
        private void Item_StateChanged(IPersistent sender, StateEventArgs args)
        {
            if (args.NewState == PersistentState.Deleted)
            {
                IReferenceObject item = (IReferenceObject)sender;

                map.Remove(item.Identity);

                item.StateChanged -= Item_StateChanged;
            }
        }
예제 #2
0
        protected void Set <TValue>(TValue value, ref TValue storage, [CallerMemberName] string propertyName = null)
        {
            if (state == PersistentState.Deleted)
            {
                return;
            }

            if (state == PersistentState.Loading)
            {
                storage = value; return;
            }

            if (state == PersistentState.New || state == PersistentState.Changed)
            {
                storage = value;
                OnPropertyChanged(propertyName);
                return;
            }

            LazyLoad(); // this code is executed for Virtual state of reference objects

            // The code below is executed for Original state only

            if (state != PersistentState.Original)
            {
                return;
            }

            bool changed = false;

            if (storage != null)
            {
                changed = !storage.Equals(value);
            }
            else
            {
                changed = (value != null);
            }

            if (changed)
            {
                StateEventArgs args = new StateEventArgs(PersistentState.Original, PersistentState.Changed);

                OnStateChanging(args);

                storage = value;

                state = PersistentState.Changed;

                OnStateChanged(args);
            }
            OnPropertyChanged(propertyName);
        }
예제 #3
0
        private void NewItem_StateChanged(IPersistent sender, StateEventArgs args)
        {
            if (args.OldState == PersistentState.New && args.NewState == PersistentState.Original)
            {
                IReferenceObject item = (IReferenceObject)sender;

                map.Add(item.Identity, item);

                item.StateChanged -= NewItem_StateChanged;

                item.StateChanged += Item_StateChanged;
            }
        }