You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

SearchResult.cs 1.4 kB

1234567891011121314151617181920212223242526272829303132333435
  1. using System.Collections.Generic;
  2. using System.Diagnostics;
  3. namespace Discord.Commands
  4. {
  5. [DebuggerDisplay(@"{DebuggerDisplay,nq}")]
  6. public struct SearchResult : IResult
  7. {
  8. public string Text { get; }
  9. public IReadOnlyList<CommandMatch> Commands { get; }
  10. public CommandError? Error { get; }
  11. public string ErrorReason { get; }
  12. public bool IsSuccess => !Error.HasValue;
  13. private SearchResult(string text, IReadOnlyList<CommandMatch> commands, CommandError? error, string errorReason)
  14. {
  15. Text = text;
  16. Commands = commands;
  17. Error = error;
  18. ErrorReason = errorReason;
  19. }
  20. public static SearchResult FromSuccess(string text, IReadOnlyList<CommandMatch> commands)
  21. => new SearchResult(text, commands, null, null);
  22. public static SearchResult FromError(CommandError error, string reason)
  23. => new SearchResult(null, null, error, reason);
  24. public static SearchResult FromError(IResult result)
  25. => new SearchResult(null, null, result.Error, result.ErrorReason);
  26. public override string ToString() => IsSuccess ? "Success" : $"{Error}: {ErrorReason}";
  27. private string DebuggerDisplay => IsSuccess ? $"Success ({Commands.Count} Results)" : $"{Error}: {ErrorReason}";
  28. }
  29. }