Exemplo n.º 1
0
        /// <summary>
        /// Adds a value to this manager to handle.
        /// </summary>
        public void AddVal(ConfValue v)
        {
            if (GetValueByName(v.Name) != null)
            {
                throw new ValueAlreadyExistsException(v.Name);
            }

            _values.Add(v);

            OnValueCreated?.Invoke(v.Name);

            // register this as the receiver for v's OnChanged
            v.OnChanged += FireValueChanged;

            // if there is a storage set, load the value from it
            if (_savedStorage != null)
            {
                v.LoadFrom(_savedStorage);
            }
        }
Exemplo n.º 2
0
        private T GetValue(bool forceNew = false)
        {
            try
            {
                if (_value != null && !forceNew)
                {
                    return(_value);
                }

                lock (_locker)
                {
                    if (forceNew || _value == null)
                    {
                        if (_value != null)
                        {
                            _value.TryDispose();
                        }

                        _value = _creator();
                    }

                    if (_value != null)
                    {
                        OnValueCreated?.Invoke(_value);
                    }
                }

                return(_value);
            }
            catch (Exception exp)
            {
                _lastException = exp;
                _value         = null;
                return(null);
            }
        }