Exemplo n.º 1
0
        /// <summary>Try to parse a keybind list from a string.</summary>
        /// <param name="input">The keybind string. See remarks on <see cref="ToString"/> for format details.</param>
        /// <param name="parsed">The parsed keybind list, if valid.</param>
        /// <param name="errors">The errors that occurred while parsing the input, if any.</param>
        public static bool TryParse(string input, out KeybindList parsed, out string[] errors)
        {
            // empty input
            if (string.IsNullOrWhiteSpace(input))
            {
                parsed = new KeybindList();
                errors = new string[0];
                return(true);
            }

            // parse buttons
            var rawErrors = new List <string>();
            var keybinds  = new List <Keybind>();

            foreach (string rawSet in input.Split(','))
            {
                if (string.IsNullOrWhiteSpace(rawSet))
                {
                    continue;
                }

                if (!Keybind.TryParse(rawSet, out Keybind keybind, out string[] curErrors))
                {
                    rawErrors.AddRange(curErrors);
                }
Exemplo n.º 2
0
 /// <summary>Parse a keybind list from a string, and throw an exception if it's not valid.</summary>
 /// <param name="input">The keybind string. See remarks on <see cref="ToString"/> for format details.</param>
 /// <exception cref="FormatException">The <paramref name="input"/> format is invalid.</exception>
 public static KeybindList Parse(string input)
 {
     return(KeybindList.TryParse(input, out KeybindList parsed, out string[] errors)
         ? parsed
         : throw new SParseException($"Can't parse {nameof(Keybind)} from invalid value '{input}'.\n{string.Join("\n", errors)}"));
 }