コード例 #1
0
        public void OptionPerLanguageOption()
        {
            var optionService = TestOptionService.GetService();
            var optionSet = optionService.GetOptions();

            Assert.Throws<System.ArgumentException>(delegate
            {
                var option = new PerLanguageOption<bool>("Test Feature", "", false);
            });

            Assert.Throws<System.ArgumentException>(delegate
            {
                var option2 = new PerLanguageOption<bool>("Test Feature", null, false);
            });

            Assert.Throws<System.ArgumentNullException>(delegate
            {
                var option3 = new PerLanguageOption<bool>(" ", "Test Name", false);
            });

            Assert.Throws<System.ArgumentNullException>(delegate
            {
                var option4 = new PerLanguageOption<bool>(null, "Test Name", false);
            });

            var optionvalid = new PerLanguageOption<bool>("Test Feature", "Test Name", false);
            Assert.Equal(false, optionSet.GetOption(optionvalid, "CS"));
        }
コード例 #2
0
        public FullSolutionAnalysisOptionBinding(IOptionService optionService, string languageName)
        {
            _optionService = optionService;
            _languageName = languageName;

            _fullSolutionAnalysis = RuntimeOptions.FullSolutionAnalysis;
            _closedFileDiagnostics = ServiceFeatureOnOffOptions.ClosedFileDiagnostic;
        }
コード例 #3
0
        protected void BindToOption(CheckBox checkbox, PerLanguageOption<bool> optionKey, string languageName)
        {
            Binding binding = new Binding();

            binding.Source = new PerLanguageOptionBinding<bool>(OptionService, optionKey, languageName);
            binding.Path = new PropertyPath("Value");
            binding.UpdateSourceTrigger = UpdateSourceTrigger.Explicit;

            var bindingExpression = checkbox.SetBinding(CheckBox.IsCheckedProperty, binding);
            _bindingExpressions.Add(bindingExpression);
        }
コード例 #4
0
        protected void BindToOption(TextBox textBox, PerLanguageOption<int> optionKey, string languageName)
        {
            Binding binding = new Binding();

            binding.Source = new PerLanguageOptionBinding<int>(OptionService, optionKey, languageName);
            binding.Path = new PropertyPath("Value");
            binding.UpdateSourceTrigger = UpdateSourceTrigger.Explicit;

            var bindingExpression = textBox.SetBinding(TextBox.TextProperty, binding);
            _bindingExpressions.Add(bindingExpression);
        }
コード例 #5
0
        internal static bool GetFeatureOnOffOption(this ITextBuffer buffer, PerLanguageOption<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;
            }
        }
コード例 #6
0
ファイル: AutomationObject.cs プロジェクト: RoryVL/roslyn
 private string GetXmlOption(PerLanguageOption<CodeStyleOption<bool>> option)
 {
     return _workspace.Options.GetOption(option, LanguageNames.CSharp).ToXElement().ToString();
 }
 private IDictionary <OptionKey, object> GetSingleRequireOption(PerLanguageOption <CodeStyleOption <ParenthesesPreference> > option)
 => OptionsSet(GetAllParenthesesOptions()
               .Where(o => o != option)
               .Select(o => SingleOption(o, RemoveIfUnnecessaryPreference))
               .Concat(SingleOption(option, RequireForPrecedenceClarityPreference)).ToArray());
コード例 #8
0
ファイル: AutomationObject.cs プロジェクト: shadmehr/roslyn
 private void SetOption <T>(PerLanguageOption <T> key, T value)
 {
     _workspace.TryApplyChanges(_workspace.CurrentSolution.WithOptions(_workspace.Options
                                                                       .WithChangedOption(key, LanguageNames.CSharp, value)));
 }
コード例 #9
0
ファイル: AutomationObject.cs プロジェクト: shadmehr/roslyn
 private T GetOption <T>(PerLanguageOption <T> key)
 {
     return(_workspace.Options.GetOption(key, LanguageNames.CSharp));
 }
コード例 #10
0
 public T GetOption <T>(PerLanguageOption <T> option, string languageName)
 {
     throw new NotImplementedException();
 }
コード例 #11
0
        public static T GetOption <T>(this AnalyzerConfigOptions analyzerConfigOptions, PerLanguageOption <T> option)
        {
            if (!TryGetEditorConfigOptionOrDefault(analyzerConfigOptions, option, out T value))
            {
                Debug.Fail("Failed to find a .editorconfig key for the option.");
                value = option.DefaultValue;
            }

            return(value);
        }
コード例 #12
0
 [return : MaybeNull] public T GetOption <T>(PerLanguageOption <T> option, string?languageName) => _globalOptionService.GetOption(option, languageName);
コード例 #13
0
ファイル: AutomationObject.cs プロジェクト: rgani/roslyn
 private void SetBooleanOption(PerLanguageOption<bool?> key, int value)
 {
     bool? boolValue = (value < 0) ? (bool?)null : (value > 0);
     var optionSet = _optionService.GetOptions();
     optionSet = optionSet.WithChangedOption(key, LanguageNames.CSharp, boolValue);
     _optionService.SetOptions(optionSet);
 }
コード例 #14
0
        public static T GetOption <T>(this AnalyzerConfigOptions analyzerConfigOptions, PerLanguageOption <T> option, string language)
        {
            // Language is not used for .editorconfig lookups
            _ = language;

            return(GetOption(analyzerConfigOptions, option));
        }
コード例 #15
0
 private Task TestMissingAsyncWithOptionAndNotificationOption(string code, PerLanguageOption <CodeStyleOption <bool> > option, NotificationOption notification)
 {
     return(TestMissingAsync(code, options: Option(option, true, notification)));
 }
コード例 #16
0
 private Task TestMissingAsyncWithOption(string code, PerLanguageOption <CodeStyleOption <bool> > option)
 {
     return(TestMissingAsyncWithOptionAndNotificationOption(code, option, NotificationOption.Error));
 }
コード例 #17
0
 public static PerLanguageOption <T> CreateRuleSpecificOption <T>(ReportingDescriptor rule, PerLanguageOption <T> option)
 {
     // This helper returns a copy of a rule option that is qualified by a new feature name constructed
     // from an arbitrary rule instance. This allows users to create a generic property descriptor
     // that is further qualified (by feature name) to be associated with a different check.
     return(new PerLanguageOption <T>(
                feature: rule.Id + "." + rule.Name.Text,
                name: option.Name,
                defaultValue: option.DefaultValue,
                description: option.Description));
 }
コード例 #18
0
 protected T GetOption <T>(ITextBuffer buffer, PerLanguageOption <T> option)
 {
     return(buffer.GetOption(option));
 }
コード例 #19
0
ファイル: AutomationObject.cs プロジェクト: RoryVL/roslyn
 private void SetBooleanOption(PerLanguageOption<bool?> key, int value)
 {
     bool? boolValue = (value < 0) ? (bool?)null : (value > 0);
     _workspace.Options = _workspace.Options.WithChangedOption(key, LanguageNames.CSharp, boolValue);
 }
コード例 #20
0
        public static T GetOption <T>(this AnalyzerConfigOptions analyzerConfigOptions, PerLanguageOption <T> option)
        {
            if (!TryGetEditorConfigOptionOrDefault(analyzerConfigOptions, option, out T value))
            {
                // There are couple of reasons this assert might fire:
                //  1. Attempting to access an option which does not have an IEditorConfigStorageLocation.
                //  2. Attempting to access an option which is not exposed from any option provider, i.e. IOptionProvider.Options.
                Debug.Fail("Failed to find a .editorconfig key for the option.");
                value = option.DefaultValue;
            }

            return(value);
        }
コード例 #21
0
 public T?GetOption <T>(PerLanguageOption <T> option, string?languageName) => _globalOptionService.GetOption(option, languageName);
コード例 #22
0
 private void SetBooleanOption(PerLanguageOption<bool> key, int value)
 {
     var optionSet = _optionService.GetOptions();
     optionSet = optionSet.WithChangedOption(key, LanguageNames.CSharp, value != 0);
     _optionService.SetOptions(optionSet);
 }
コード例 #23
0
 protected IDictionary <OptionKey, object> Option(PerLanguageOption <CodeStyle.CodeStyleOption <bool> > option, bool value, CodeStyle.NotificationOption notification)
 {
     return(OptionsSet(Tuple.Create(option, value, notification)));
 }
コード例 #24
0
        private DiagnosticDescriptor GetApplicablePredefinedTypeDiagnosticDescriptor <T>(string id, PerLanguageOption <T> option, OptionSet optionSet) where T : CodeStyleOption <bool>
        {
            var optionValue = optionSet.GetOption(option, GetLanguageName());

            DiagnosticDescriptor descriptor = null;

            if (optionValue.Notification.Value != DiagnosticSeverity.Hidden)
            {
                descriptor = new DiagnosticDescriptor(id,
                                                      s_localizableTitleSimplifyNames,
                                                      s_localizableMessage,
                                                      DiagnosticCategory.Style,
                                                      optionValue.Notification.Value,
                                                      isEnabledByDefault: true,
                                                      customTags: DiagnosticCustomTags.Unnecessary);
            }

            return(descriptor);
        }
コード例 #25
0
 public T GetOption <T>(PerLanguageOption <T> option, string language) => _optionSet.GetOption(option, language);
コード例 #26
0
 static void ResetPerLanguageOption <T>(IGlobalOptionService globalOptions, PerLanguageOption <T> option)
 {
     globalOptions.SetGlobalOption(new OptionKey(option, LanguageNames.CSharp), option.DefaultValue);
     globalOptions.SetGlobalOption(new OptionKey(option, LanguageNames.VisualBasic), option.DefaultValue);
 }
コード例 #27
0
        public void SetOption <T>(PerLanguageOption <T> option, string language, T value)
        {
            _optionSet = _optionSet.WithChangedOption(option, language, value);

            OnOptionChanged(new OptionKey(option, language));
        }
コード例 #28
0
ファイル: AutomationObject.cs プロジェクト: shadmehr/roslyn
 private int GetBooleanOption(PerLanguageOption <bool> key)
 {
     return(_workspace.Options.GetOption(key, LanguageNames.CSharp) ? 1 : 0);
 }
コード例 #29
0
 private void SetBooleanOption(PerLanguageOption <bool> key, int value)
 {
     _workspace.Options = _workspace.Options.WithChangedOption(key, LanguageNames.CSharp, value != 0);
 }
コード例 #30
0
ファイル: AutomationObject.cs プロジェクト: shadmehr/roslyn
 private void SetBooleanOption(PerLanguageOption <bool> key, int value)
 {
     _workspace.TryApplyChanges(_workspace.CurrentSolution.WithOptions(_workspace.Options
                                                                       .WithChangedOption(key, LanguageNames.CSharp, value != 0)));
 }
コード例 #31
0
 private void SetOption <T>(PerLanguageOption <T> key, T value)
 {
     _workspace.Options = _workspace.Options.WithChangedOption(key, LanguageNames.CSharp, value);
 }
コード例 #32
0
ファイル: AutomationObject.cs プロジェクト: shadmehr/roslyn
 private string GetXmlOption(PerLanguageOption <CodeStyleOption <bool> > option)
 {
     return(_workspace.Options.GetOption(option, LanguageNames.CSharp).ToXElement().ToString());
 }
コード例 #33
0
        private void SetBooleanOption(PerLanguageOption <bool?> key, int value)
        {
            var boolValue = (value < 0) ? (bool?)null : (value > 0);

            _workspace.Options = _workspace.Options.WithChangedOption(key, LanguageNames.CSharp, boolValue);
        }
コード例 #34
0
        private void SetXmlOption(PerLanguageOption <CodeStyleOption <bool> > option, string value)
        {
            var convertedValue = CodeStyleOption <bool> .FromXElement(XElement.Parse(value));

            _workspace.Options = _workspace.Options.WithChangedOption(option, LanguageNames.CSharp, convertedValue);
        }
コード例 #35
0
 public PerLanguageOptionBinding(IOptionService optionService, PerLanguageOption <T> key, string languageName)
 {
     _optionService = optionService;
     _key           = key;
     _languageName  = languageName;
 }
コード例 #36
0
ファイル: AutomationObject.cs プロジェクト: RoryVL/roslyn
 private int GetBooleanOption(PerLanguageOption<bool> key)
 {
     return _workspace.Options.GetOption(key, LanguageNames.CSharp) ? 1 : 0;
 }
コード例 #37
0
 private Task TestMissingAsyncWithOption(string code, PerLanguageOption<CodeStyleOption<bool>> option)
 {
     return TestMissingAsyncWithOptionAndNotificationOption(code, option, NotificationOption.Error);
 }
コード例 #38
0
ファイル: AutomationObject.cs プロジェクト: RoryVL/roslyn
 private void SetBooleanOption(PerLanguageOption<bool> key, int value)
 {
     _workspace.Options = _workspace.Options.WithChangedOption(key, LanguageNames.CSharp, value != 0);
 }
コード例 #39
0
 private Task TestMissingAsyncWithOptionAndNotificationOption(string code, PerLanguageOption<CodeStyleOption<bool>> option, NotificationOption notification)
 {
     return TestMissingAsync(code, options: Option(option, true, notification));
 }
コード例 #40
0
ファイル: AutomationObject.cs プロジェクト: RoryVL/roslyn
 private void SetXmlOption(PerLanguageOption<CodeStyleOption<bool>> option, string value)
 {
     var convertedValue = CodeStyleOption<bool>.FromXElement(XElement.Parse(value));
     _workspace.Options = _workspace.Options.WithChangedOption(option, LanguageNames.CSharp, convertedValue);
 }
コード例 #41
0
        private bool IsFrameworkTypePreferred(OptionSet optionSet, PerLanguageOption <CodeStyleOption <bool> > option, string language)
        {
            var optionValue = optionSet.GetOption(option, language);

            return(OptionSettingPrefersFrameworkType(optionValue, optionValue.Notification.Value));
        }
コード例 #42
0
ファイル: AutomationObject.cs プロジェクト: rgani/roslyn
        private int GetBooleanOption(PerLanguageOption<bool?> key)
        {
            var option = _optionService.GetOption(key, LanguageNames.CSharp);
            if (!option.HasValue)
            {
                return -1;
            }

            return option.Value ? 1 : 0;
        }
コード例 #43
0
        /// <summary>
        /// Find the <see cref="CodeStyleOption{T}"/> for <paramref name="key"/>.
        /// </summary>
        /// <typeparam name="T">The type of the value.</typeparam>
        /// <param name="document">The <see cref="Document"/>.</param>
        /// <param name="key">The <see cref="CodeStyleOption{T}"/> for c#.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> that cancels the operation.</param>
        /// <returns><see cref="CodeStyleOption{T}"/> or null if not found.</returns>
        public static async Task <CodeStyleOption <T>?> FindInEditorConfigAsync <T>(Document document, PerLanguageOption <CodeStyleOption <T> > key, CancellationToken cancellationToken)
        {
            if (document is null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            if (key is null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            var optionSet = await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false);

            if (optionSet.GetOption(key, document.Project.Language) is { } option&&
                !ReferenceEquals(option, key.DefaultValue))
            {
                return(option);
            }

            return(null);
        }
コード例 #44
0
 private int GetBooleanOption(PerLanguageOption<bool> key)
 {
     return _optionService.GetOption(key, LanguageNames.CSharp) ? 1 : 0;
 }
コード例 #45
0
ファイル: AutomationObject.cs プロジェクト: tsasioglu/roslyn
 private int GetBooleanOption(PerLanguageOption <bool> key)
 {
     return(_optionService.GetOption(key, LanguageNames.CSharp) ? 1 : 0);
 }
コード例 #46
0
 protected IDictionary<OptionKey, object> Option(PerLanguageOption<CodeStyle.CodeStyleOption<bool>> option, bool value, CodeStyle.NotificationOption notification)
 {
     return OptionsSet(Tuple.Create(option, value, notification));
 }
コード例 #47
0
ファイル: OptionExtensions.cs プロジェクト: jkotas/roslyn
 internal static IDictionary<OptionKey, object> With(this IDictionary<OptionKey, object> options, PerLanguageOption<CodeStyleOption<bool>> option, object value, string language)
 {
     options.Add(new OptionKey(option, language), value);
     return options;
 }