internal override IEnumerable <OptionKey> GetChangedOptions(OptionSet?optionSet)
            {
                if (optionSet == this)
                {
                    yield break;
                }

                foreach (var(key, value) in _values)
                {
                    var currentValue = optionSet?.GetOption(key);
                    if (!object.Equals(currentValue, value))
                    {
                        yield return(key);
                    }
                }
            }
Exemplo n.º 2
0
 private protected override object?GetOptionCore(OptionKey optionKey) =>
 _backingOptionSet.GetOption(optionKey);
Exemplo n.º 3
0
 public override object GetOption(OptionKey optionKey)
 {
     return(_backingOptionSet.GetOption(optionKey));
 }
        public void SetOptions(OptionSet optionSet)
        {
            if (optionSet == null)
            {
                throw new ArgumentNullException(nameof(optionSet));
            }

            var workspaceOptionSet = optionSet as WorkspaceOptionSet;

            if (workspaceOptionSet == null)
            {
                throw new ArgumentException(WorkspacesResources.OptionsDidNotComeFromWorkspace, paramName: nameof(optionSet));
            }

            var changedOptions = new List <OptionChangedEventArgs>();

            lock (_gate)
            {
                foreach (var optionKey in workspaceOptionSet.GetAccessedOptions())
                {
                    var    setValue     = optionSet.GetOption(optionKey);
                    object currentValue = this.GetOption(optionKey);

                    if (object.Equals(currentValue, setValue))
                    {
                        // Identical, so nothing is changing
                        continue;
                    }

                    // The value is actually changing, so update
                    changedOptions.Add(new OptionChangedEventArgs(optionKey, setValue));

                    _currentValues = _currentValues.SetItem(optionKey, setValue);

                    ImmutableArray <Lazy <IOptionSerializer, OptionSerializerMetadata> > optionSerializers;
                    if (_featureNameToOptionSerializers.TryGetValue(optionKey.Option.Feature, out optionSerializers))
                    {
                        foreach (var serializer in optionSerializers)
                        {
                            // There can be options (ex, formatting) that only exist in only one specific language. In those cases,
                            // feature's serializer should exist in only that language.
                            if (!SupportedSerializer(optionKey, serializer.Metadata))
                            {
                                continue;
                            }

                            if (serializer.Value.TryPersist(optionKey, setValue))
                            {
                                break;
                            }
                        }
                    }
                }
            }

            // Outside of the lock, raise events
            var optionChanged = OptionChanged;

            if (optionChanged != null)
            {
                foreach (var changedOption in changedOptions)
                {
                    optionChanged(this, changedOption);
                }
            }
        }