private protected void BindToOption(TextBox textBox, PerLanguageOption2 <int> optionKey, string languageName)
        {
            var binding = new Binding()
            {
                Source = new PerLanguageOptionBinding <int>(OptionStore, optionKey, languageName),
                Path   = new PropertyPath("Value"),
                UpdateSourceTrigger = UpdateSourceTrigger.Default
            };

            var bindingExpression = textBox.SetBinding(TextBox.TextProperty, binding);

            _bindingExpressions.Add(bindingExpression);
        }
示例#2
0
 public PerLanguageEnumCodeStyleSetting(PerLanguageOption2 <CodeStyleOption2 <T> > option,
                                        string description,
                                        T[] enumValues,
                                        string[] valueDescriptions,
                                        AnalyzerConfigOptions editorConfigOptions,
                                        OptionSet visualStudioOptions,
                                        OptionUpdater updater)
     : base(description, enumValues, valueDescriptions, option.Group.Description, updater)
 {
     _option = option;
     _editorConfigOptions = editorConfigOptions;
     _visualStudioOptions = visualStudioOptions;
 }
        private protected void BindToOption(CheckBox checkbox, PerLanguageOption2 <bool> optionKey, string languageName)
        {
            var binding = new Binding()
            {
                Source = new PerLanguageOptionBinding <bool>(OptionStore, optionKey, languageName),
                Path   = new PropertyPath("Value"),
                UpdateSourceTrigger = UpdateSourceTrigger.Default
            };

            var bindingExpression = checkbox.SetBinding(CheckBox.IsCheckedProperty, binding);

            _bindingExpressions.Add(bindingExpression);
        }
 /// <summary>
 /// Constructor for an unnecessary code style analyzer with a single diagnostic descriptor and
 /// unique <see cref="ISingleValuedOption"/> code style option for the given language.
 /// </summary>
 /// <param name="diagnosticId">Diagnostic ID reported by this analyzer</param>
 /// <param name="enforceOnBuild">Build enforcement recommendation for this analyzer</param>
 /// <param name="option">
 /// Language specific option that can be used to configure the given <paramref name="diagnosticId"/>.
 /// <see langword="null"/>, if there is no such unique option.
 /// </param>
 /// <param name="fadingOption">
 /// Per-language fading option that can be used to configure if the diagnostic should be faded in the IDE or not.
 /// <see langword="null"/>, if there is no such unique fading option.
 /// </param>
 /// <param name="language">Language for the given language-specific <paramref name="option"/>.</param>
 /// <param name="title">Title for the diagnostic descriptor</param>
 /// <param name="messageFormat">
 /// Message for the diagnostic descriptor.
 /// <see langword="null"/> if the message is identical to the title.
 /// </param>
 /// <param name="configurable">Flag indicating if the reported diagnostics are configurable by the end users</param>
 protected AbstractBuiltInUnnecessaryCodeStyleDiagnosticAnalyzer(
     string diagnosticId,
     EnforceOnBuild enforceOnBuild,
     ISingleValuedOption?option,
     PerLanguageOption2 <bool>?fadingOption,
     string language,
     LocalizableString title,
     LocalizableString?messageFormat = null,
     bool configurable = true)
     : base(diagnosticId, enforceOnBuild, option, language, title, messageFormat, isUnnecessary: true, configurable)
 {
     AddDiagnosticIdToFadingOptionMapping(diagnosticId, fadingOption);
 }
示例#5
0
        private protected void BindToOption(CheckBox checkbox, PerLanguageOption2 <bool?> nullableOptionKey, string languageName, Func <bool> onNullValue)
        {
            var binding = new Binding()
            {
                Source = new PerLanguageOptionBinding <bool?>(OptionStore, nullableOptionKey, languageName),
                Path   = new PropertyPath("Value"),
                UpdateSourceTrigger = UpdateSourceTrigger.Default,
                Converter           = new NullableBoolOptionConverter(onNullValue)
            };

            var bindingExpression = checkbox.SetBinding(CheckBox.IsCheckedProperty, binding);

            _bindingExpressions.Add(bindingExpression);
        }
        private protected void BindToOption <T>(ComboBox comboBox, PerLanguageOption2 <T> optionKey, string languageName)
        {
            var binding = new Binding()
            {
                Source             = new PerLanguageOptionBinding <T>(OptionStore, optionKey, languageName),
                Path               = new PropertyPath("Value"),
                Converter          = new ComboBoxItemTagToIndexConverter(),
                ConverterParameter = comboBox
            };

            var bindingExpression = comboBox.SetBinding(ComboBox.SelectedIndexProperty, binding);

            _bindingExpressions.Add(bindingExpression);
        }
示例#7
0
 public EnumCodeStyleOptionViewModel(
     PerLanguageOption2 <CodeStyleOption2 <T> > option,
     string language,
     string description,
     T[] enumValues,
     string[] previews,
     AbstractOptionPreviewViewModel info,
     OptionStore optionStore,
     string groupName,
     List <CodeStylePreference> preferences)
     : this((IOption)option, language, description, enumValues, previews, info,
            optionStore, groupName, preferences)
 {
 }
示例#8
0
        public PerLanguageOptionBinding(OptionStore optionStore, PerLanguageOption2 <T> key, string languageName)
        {
            _optionStore  = optionStore;
            _key          = key;
            _languageName = languageName;

            _optionStore.OptionChanged += (sender, e) =>
            {
                if (e.Option == _key)
                {
                    PropertyChanged?.Raise(this, new PropertyChangedEventArgs(nameof(Value)));
                }
            };
        }
示例#9
0
 public static T GetOption <T>(
     this AnalyzerOptions analyzerOptions,
     PerLanguageOption2 <T> option,
     string?language,
     SyntaxTree syntaxTree,
     CancellationToken cancellationToken
     ) =>
 GetOption <T>(
     analyzerOptions,
     (IOption2)option,
     language,
     syntaxTree,
     cancellationToken
     );
 public PerLanguageBooleanCodeStyleSetting(PerLanguageOption2 <CodeStyleOption2 <bool> > option,
                                           string description,
                                           string?trueValueDescription,
                                           string?falseValueDescription,
                                           AnalyzerConfigOptions editorConfigOptions,
                                           OptionSet visualStudioOptions,
                                           OptionUpdater updater,
                                           string fileName)
     : base(description, option.Group.Description, trueValueDescription, falseValueDescription, updater)
 {
     _option = option;
     _editorConfigOptions = editorConfigOptions;
     _visualStudioOptions = visualStudioOptions;
     Location             = new SettingLocation(IsDefinedInEditorConfig ? LocationKind.EditorConfig : LocationKind.VisualStudio, fileName);
 }
        private protected void BindToOption <T>(RadioButton radiobutton, PerLanguageOption2 <T> optionKey, T optionValue, string languageName)
        {
            var binding = new Binding()
            {
                Source = new PerLanguageOptionBinding <T>(OptionStore, optionKey, languageName),
                Path   = new PropertyPath("Value"),
                UpdateSourceTrigger = UpdateSourceTrigger.Default,
                Converter           = new RadioButtonCheckedConverter(),
                ConverterParameter  = optionValue
            };

            var bindingExpression = radiobutton.SetBinding(RadioButton.IsCheckedProperty, binding);

            _bindingExpressions.Add(bindingExpression);
        }
        private OptionsCollection GetSingleRequireOption(PerLanguageOption2 <CodeStyleOption2 <ParenthesesPreference> > option)
        {
            var optionsCollection = new OptionsCollection(_language);

            foreach (var o in GetAllParenthesesOptions())
            {
                if (o != option)
                {
                    optionsCollection.Add(o, RemoveIfUnnecessaryPreference);
                }
            }

            optionsCollection.Add(option, RequireForPrecedenceClarityPreference);
            return(optionsCollection);
        }
示例#13
0
 public static PerLanguageFormattingSetting <TOption> Create <TOption>(
     PerLanguageOption2 <TOption> option,
     string description,
     AnalyzerConfigOptions editorConfigOptions,
     OptionSet visualStudioOptions,
     OptionUpdater updater
     ) where TOption : notnull
 {
     return(new PerLanguageFormattingSetting <TOption>(
                option,
                description,
                editorConfigOptions,
                visualStudioOptions,
                updater
                ));
 }
示例#14
0
            public PerLanguageEnumCodeStyleSetting(PerLanguageOption2 <CodeStyleOption2 <T> > option,
                                                   string description,
                                                   T[] enumValues,
                                                   string[] valueDescriptions,
                                                   AnalyzerConfigOptions editorConfigOptions,
                                                   OptionSet visualStudioOptions,
                                                   OptionUpdater updater,
                                                   string fileName)
                : base(description, enumValues, valueDescriptions, option.Group.Description, updater)
            {
                _option = option;

                _editorConfigOptions = editorConfigOptions;
                _visualStudioOptions = visualStudioOptions;
                Location             = new SettingLocation(IsDefinedInEditorConfig ? LocationKind.EditorConfig : LocationKind.VisualStudio, fileName);
            }
示例#15
0
        private static PerLanguageOption2 <T> CreatePerLanguageOption <T>(
            OptionGroup group,
            string name,
            T defaultValue,
            params OptionStorageLocation2[] storageLocations
            )
        {
            var option = new PerLanguageOption2 <T>(
                nameof(FormattingOptions),
                group,
                name,
                defaultValue,
                storageLocations
                );

            s_allOptionsBuilder.Add(option);
            return(option);
        }
示例#16
0
        internal static bool GetFeatureOnOffOption(this ITextBuffer buffer, PerLanguageOption2 <bool> option)
        {
            // Add a FailFast to help diagnose 984249.  Hopefully this will let us know what the issue is.
            try
            {
                var document = buffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges();

                if (document != null)
                {
                    return(document.Project.Solution.Options.GetOption(option, document.Project.Language));
                }

                return(option.DefaultValue);
            }
            catch (Exception e) when(FatalError.Report(e))
            {
                throw ExceptionUtilities.Unreachable;
            }
        }
        protected void AddParenthesesOption(
            string language,
            OptionStore optionStore,
            PerLanguageOption2 <CodeStyleOption2 <ParenthesesPreference> > languageOption,
            string title,
            string[] examples,
            bool defaultAddForClarity
            )
        {
            var preferences          = new List <ParenthesesPreference>();
            var codeStylePreferences = new List <CodeStylePreference>();

            preferences.Add(ParenthesesPreference.AlwaysForClarity);
            codeStylePreferences.Add(
                new CodeStylePreference(
                    ServicesVSResources.Always_for_clarity,
                    isChecked: defaultAddForClarity
                    )
                );

            preferences.Add(ParenthesesPreference.NeverIfUnnecessary);
            codeStylePreferences.Add(
                new CodeStylePreference(
                    ServicesVSResources.Never_if_unnecessary,
                    isChecked: !defaultAddForClarity
                    )
                );

            CodeStyleItems.Add(
                new EnumCodeStyleOptionViewModel <ParenthesesPreference>(
                    languageOption,
                    language,
                    title,
                    preferences.ToArray(),
                    examples,
                    this,
                    optionStore,
                    ServicesVSResources.Parentheses_preferences_colon,
                    codeStylePreferences
                    )
                );
        }
示例#18
0
 internal static CodeStyleSetting Create(
     PerLanguageOption2 <CodeStyleOption2 <bool> > option,
     string description,
     AnalyzerConfigOptions editorConfigOptions,
     OptionSet visualStudioOptions,
     OptionUpdater updater,
     string?trueValueDescription  = null,
     string?falseValueDescription = null
     )
 {
     return(new PerLanguageBooleanCodeStyleSetting(
                option,
                description,
                trueValueDescription,
                falseValueDescription,
                editorConfigOptions,
                visualStudioOptions,
                updater
                ));
 }
示例#19
0
 internal static CodeStyleSetting Create <T>(
     PerLanguageOption2 <CodeStyleOption2 <T> > option,
     string description,
     T[] enumValues,
     string[] valueDescriptions,
     AnalyzerConfigOptions editorConfigOptions,
     OptionSet visualStudioOptions,
     OptionUpdater updater
     ) where T : Enum
 {
     return(new PerLanguageEnumCodeStyleSetting <T>(
                option,
                description,
                enumValues,
                valueDescriptions,
                editorConfigOptions,
                visualStudioOptions,
                updater
                ));
 }
示例#20
0
 protected AbstractUseConditionalExpressionDiagnosticAnalyzer(
     string descriptorId,
     EnforceOnBuild enforceOnBuild,
     LocalizableResourceString message,
     PerLanguageOption2 <CodeStyleOption2 <bool> > option
     )
     : base(
         descriptorId,
         enforceOnBuild,
         option,
         new LocalizableResourceString(
             nameof(AnalyzersResources.Convert_to_conditional_expression),
             AnalyzersResources.ResourceManager,
             typeof(AnalyzersResources)
             ),
         message
         )
 {
     _option = option;
 }
 public PerLanguageBooleanCodeStyleSetting(
     PerLanguageOption2 <CodeStyleOption2 <bool> > option,
     string description,
     string?trueValueDescription,
     string?falseValueDescription,
     AnalyzerConfigOptions editorConfigOptions,
     OptionSet visualStudioOptions,
     OptionUpdater updater
     )
     : base(
         description,
         option.Group.Description,
         trueValueDescription,
         falseValueDescription,
         updater
         )
 {
     _option = option;
     _editorConfigOptions = editorConfigOptions;
     _visualStudioOptions = visualStudioOptions;
 }
示例#22
0
 public static T GetOption <T>(this AnalyzerConfigOptions analyzerConfigOptions, PerLanguageOption2 <T> option)
 => GetOptionWithAssertOnFailure <T>(analyzerConfigOptions, option);
示例#23
0
        public static T GetOption <T>(this AnalyzerConfigOptions analyzerConfigOptions, PerLanguageOption2 <T> option, string language)
        {
            // Language is not used for .editorconfig lookups
            _ = language;

            return(GetOption(analyzerConfigOptions, option));
        }
 private TValue GetOption <TValue>(PerLanguageOption2 <TValue> option, TValue defaultValue)
 => _options.GetEditorConfigOption(option, defaultValue);
示例#25
0
 private void SetBooleanOption(PerLanguageOption2 <bool> key, int value)
 => SetOption(key, value != 0);
示例#26
0
 private int GetBooleanOption(PerLanguageOption2 <bool> key)
 => GetOption(key) ? 1 : 0;
示例#27
0
 public void Add <T>(PerLanguageOption2 <CodeStyleOption2 <T> > option, T value) =>
 Add(option, value, option.DefaultValue.Notification);
示例#28
0
 public void Add <T>(PerLanguageOption2 <T> option, T value) =>
 _options.Add(new OptionKey2(option, _languageName), value);
示例#29
0
 public void Add <T>(PerLanguageOption2 <CodeStyleOption2 <T> > option, T value, NotificationOption2 notification)
 => _options.Add(new OptionKey2(option, _languageName), new CodeStyleOption2 <T>(value, notification));
 public T GetOption <T>(PerLanguageOption2 <T> option, string languageName)
 {
     throw new NotImplementedException();
 }