Implemented command type readers, parser and service.

This commit is contained in:
RogueException
2016-06-26 03:35:40 -03:00
parent d934a5a1eb
commit f59b6b9004
19 changed files with 775 additions and 42 deletions

View File

@@ -0,0 +1,35 @@
using System.Collections.Generic;
using System.Diagnostics;
namespace Discord.Commands
{
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public struct ParseResult : IResult
{
public IReadOnlyList<object> Values { get; }
public CommandError? Error { get; }
public string ErrorReason { get; }
public bool IsSuccess => !Error.HasValue;
private ParseResult(IReadOnlyList<object> values, CommandError? error, string errorReason)
{
Values = values;
Error = error;
ErrorReason = errorReason;
}
internal static ParseResult FromSuccess(IReadOnlyList<object> values)
=> new ParseResult(values, null, null);
internal static ParseResult FromError(CommandError error, string reason)
=> new ParseResult(null, error, reason);
internal static ParseResult FromError(SearchResult result)
=> new ParseResult(null, result.Error, result.ErrorReason);
internal static ParseResult FromError(TypeReaderResult result)
=> new ParseResult(null, result.Error, result.ErrorReason);
public override string ToString() => IsSuccess ? "Success" : $"{Error}: {ErrorReason}";
private string DebuggerDisplay => IsSuccess ? $"Success ({Values.Count} Values)" : $"{Error}: {ErrorReason}";
}
}