Пример #1
0
        /// <summary>
        /// Given an editor-config code-style-option, gives back the constituent parts of the
        /// option.  For example, if the option is "true:error" then "true" will be returned
        /// in <paramref name="value"/> and <see cref="NotificationOption.Error"/> will be returned
        /// in <paramref name="notificationOpt"/>.  Note that users are allowed to not provide
        /// a NotificationOption, so <paramref name="notificationOpt"/> may be null.  The caller
        /// of this method must decide what to do in that case.
        /// </summary>
        public static bool TryGetCodeStyleValueAndOptionalNotification(
            string arg, out string value, out NotificationOption notificationOpt)
        {
            var args = arg.Split(':');

            Debug.Assert(args.Length > 0);

            // We allow a single value to be provided in some cases.  For example users
            // can provide 'false' without supplying a notification as well.  Allow the
            // caller of this to determine what to do in this case.
            if (args.Length == 1)
            {
                value           = args[0].Trim();
                notificationOpt = null;
                return(true);
            }

            if (args.Length == 2)
            {
                // If we have two args, then the second must be a notification option.  If
                // it isn't, then this isn't a valid code style option at all.
                if (TryParseNotification(args[1], out var localNotification))
                {
                    value           = args[0].Trim();
                    notificationOpt = localNotification;
                    return(true);
                }
            }

            // We only support 0 or 1 args.  Anything else can't be parsed properly.
            value           = null;
            notificationOpt = null;
            return(false);
        }
 public static string ToEditorConfigString(this NotificationOption notificationOption)
 {
     return(notificationOption.Severity switch
     {
         ReportDiagnostic.Suppress => EditorConfigSeverityStrings.None,
         ReportDiagnostic.Hidden => EditorConfigSeverityStrings.Silent,
         ReportDiagnostic.Info => EditorConfigSeverityStrings.Suggestion,
         ReportDiagnostic.Warn => EditorConfigSeverityStrings.Warning,
         ReportDiagnostic.Error => EditorConfigSeverityStrings.Error,
         _ => throw ExceptionUtilities.UnexpectedValue(notificationOption.Severity)
     });
Пример #3
0
        public static bool TryParseNotification(string value, out NotificationOption notification)
        {
            switch (value.Trim())
            {
            case EditorConfigSeverityStrings.Silent: notification = NotificationOption.None; return(true);

            case EditorConfigSeverityStrings.Suggestion: notification = NotificationOption.Suggestion; return(true);

            case EditorConfigSeverityStrings.Warning: notification = NotificationOption.Warning; return(true);

            case EditorConfigSeverityStrings.Error: notification = NotificationOption.Error; return(true);
            }

            notification = NotificationOption.None;
            return(false);
        }
Пример #4
0
 public CodeStyleOption(T value, NotificationOption notification)
 {
     Value        = value;
     Notification = notification;
 }
 public static string ToEditorConfigString(this NotificationOption notificationOption)
 => notificationOption.Severity.ToEditorConfigString();
 protected IDictionary<OptionKey, object> Option(IOption option, bool value, NotificationOption notification)
     => OptionsSet(Tuple.Create(option, value, notification));
 public NotificationOptionViewModel(NotificationOption notification, ImageMoniker moniker)
 {
     Notification = notification;
     Name = notification.Name;
     Moniker = moniker;
 }
Пример #8
0
 private Task TestMissingAsyncWithOptionAndNotificationOption(string code, PerLanguageOption<CodeStyleOption<bool>> option, NotificationOption notification)
 {
     return TestMissingAsync(code, options: Option(option, true, notification));
 }
 private IDictionary<OptionKey, object> QualifyMethodAccessWithNotification(NotificationOption notification)
     => new Dictionary<OptionKey, object>() { { new OptionKey(CodeStyleOptions.QualifyMethodAccess, LanguageNames.CSharp), new CodeStyleOption<bool>(true, notification) } };
Пример #10
0
 public CodeStyleOption(T value, NotificationOption notification)
 {
     Value        = value;
     Notification = notification ?? throw new ArgumentNullException(nameof(notification));
 }