Пример #1
0
        // TODO: what we actually need for _handlers is not a list of delegates
        // but a list of WeakDelegates (Delegate with WeakReference to it's target).
        // Unfortunately the .Net Framework doesn't provide such a thing yet afaik...

        #region Property Aspects
        public void SetProperty(TProperty property, object value)
        {
            //if(!property.IsValidValue(value))
            //    throw new ArgumentException();
            if (_properties == null)
            {
                _properties            = new Dictionary <TProperty, Dirtyable <object> >();
                _propertyEventTriggers = new Dictionary <TEvent, List <TriggerableEventTrigger <TIdentifier, TEvent, TProperty, TFlag, TProperty> > >();
            }

            Dirtyable <object> old;
            object             oldValue = null;

            if (_properties.TryGetValue(property, out old))
            {
                oldValue = old.Value;
            }
            else
            {
                WirePropertyEventTriggers(property);
            }

            _properties[property] = new Dirtyable <object>(value);

            if (value != oldValue)
            {
                property.RaisePropertyChanged((TObject)this, oldValue, value);
            }
        }
Пример #2
0
        public void SetFlagState(TFlag flag, FlagState state)
        {
            if (_flags == null)
            {
                if (state == FlagState.Unknown)
                {
                    return;
                }
                _flags             = new Dictionary <TFlag, Dirtyable <bool> >();
                _flagEventTriggers = new Dictionary <TEvent, List <TriggerableEventTrigger <TIdentifier, TEvent, TFlag, TFlag, TProperty> > >();
            }
            FlagState oldState = GetFlagState(flag);

            if (state == FlagState.Unknown)
            {
                UnwireFlagEventTriggers(flag);
                _flags.Remove(flag);
            }
            else
            {
                if (!_flags.ContainsKey(flag))
                {
                    WireFlagEventTriggers(flag);
                }
                _flags[flag] = new Dirtyable <bool>(state == FlagState.Enabled);
            }

            if (oldState != state)
            {
                flag.RaiseFlagChanged((TObject)this, oldState, state);
            }
        }
Пример #3
0
        public void DisableFlag(TFlag flag)
        {
            if (_flags == null)
            {
                _flags             = new Dictionary <TFlag, Dirtyable <bool> >();
                _flagEventTriggers = new Dictionary <TEvent, List <TriggerableEventTrigger <TIdentifier, TEvent, TFlag, TFlag, TProperty> > >();
            }
            FlagState oldState = GetFlagState(flag);

            if (!_flags.ContainsKey(flag))
            {
                WireFlagEventTriggers(flag);
            }
            _flags[flag] = new Dirtyable <bool>(false);

            if (oldState != FlagState.Disabled)
            {
                flag.RaiseFlagChanged((TObject)this, oldState, FlagState.Disabled);
            }
        }