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.

PreconditionResult.cs 1.1 kB

1234567891011121314151617181920212223242526272829
  1. using System.Diagnostics;
  2. namespace Discord.Commands
  3. {
  4. [DebuggerDisplay(@"{DebuggerDisplay,nq}")]
  5. public class PreconditionResult : IResult
  6. {
  7. public CommandError? Error { get; }
  8. public string ErrorReason { get; }
  9. public bool IsSuccess => !Error.HasValue;
  10. protected PreconditionResult(CommandError? error, string errorReason)
  11. {
  12. Error = error;
  13. ErrorReason = errorReason;
  14. }
  15. public static PreconditionResult FromSuccess()
  16. => new PreconditionResult(null, null);
  17. public static PreconditionResult FromError(string reason)
  18. => new PreconditionResult(CommandError.UnmetPrecondition, reason);
  19. public static PreconditionResult FromError(IResult result)
  20. => new PreconditionResult(result.Error, result.ErrorReason);
  21. public override string ToString() => IsSuccess ? "Success" : $"{Error}: {ErrorReason}";
  22. private string DebuggerDisplay => IsSuccess ? "Success" : $"{Error}: {ErrorReason}";
  23. }
  24. }