コード例 #1
0
        /// <summary>
        /// Determines whether an option schema matches specified alias.
        /// </summary>
        public static bool MatchesAlias(this CommandOptionSchema optionSchema, string alias)
        {
            // Compare against name. Case is ignored.
            var matchesByName =
                !string.IsNullOrWhiteSpace(optionSchema.Name) &&
                string.Equals(optionSchema.Name, alias, StringComparison.OrdinalIgnoreCase);

            // Compare against short name. Case is NOT ignored.
            var matchesByShortName =
                optionSchema.ShortName != null &&
                alias.Length == 1 && alias[0] == optionSchema.ShortName;

            return(matchesByName || matchesByShortName);
        }
コード例 #2
0
        /// <summary>
        /// Gets valid aliases for the option.
        /// </summary>
        public static IReadOnlyList <string> GetAliases(this CommandOptionSchema optionSchema)
        {
            var result = new List <string>(2);

            if (!string.IsNullOrWhiteSpace(optionSchema.Name))
            {
                result.Add(optionSchema.Name !);
            }

            if (optionSchema.ShortName != null)
            {
                result.Add(optionSchema.ShortName.Value.AsString());
            }

            return(result);
        }
コード例 #3
0
 /// <summary>
 /// Finds an option input that matches the option schema specified, or null if not found.
 /// </summary>
 public static CommandOptionInput?FindByOptionSchema(this IReadOnlyList <CommandOptionInput> optionInputs, CommandOptionSchema optionSchema) =>
 optionInputs.FirstOrDefault(o => optionSchema.MatchesAlias(o.Alias));