예제 #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="NotificationOption2.Error"/> will be returned
        /// in <paramref name="notification"/>.  Note that users are allowed to not provide
        /// a NotificationOption, so <paramref name="notification"/> will default to <paramref name="defaultNotification"/>.
        /// </summary>
        public static bool TryGetCodeStyleValueAndOptionalNotification(
            string arg, NotificationOption2 defaultNotification, [NotNullWhen(true)] out string?value, [NotNullWhen(true)] out NotificationOption2?notification)
        {
            var args = arg.Split(':');

            Debug.Assert(args.Length > 0);

            // We allow a single value to be provided without an explicit notification.
            if (args.Length == 1)
            {
                value        = args[0].Trim();
                notification = defaultNotification;
                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();
                    notification = localNotification;
                    return(true);
                }
            }

            // We only support 0 or 1 args.  Anything else can't be parsed properly.
            value        = null;
            notification = null;
            return(false);
        }
예제 #2
0
        public static bool TryGetCodeStyleValueAndOptionalNotification(
            string arg, out string value, out NotificationOption2 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);
        }
예제 #3
0
        private static bool TryParseNotification(string value, out NotificationOption2 notification)
        {
            switch (value.Trim())
            {
            case EditorConfigSeverityStrings.None:
                notification = NotificationOption2.None;
                return(true);

            case EditorConfigSeverityStrings.Refactoring:
            case EditorConfigSeverityStrings.Silent:
                notification = NotificationOption2.Silent;
                return(true);

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

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

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

            notification = NotificationOption2.Silent;
            return(false);
        }
예제 #4
0
 public static string ToEditorConfigString(this NotificationOption2 notificationOption)
 => notificationOption.Severity.ToEditorConfigString();