From 3923b7bb20bcc60e8b568f43dc7279e73a19929b Mon Sep 17 00:00:00 2001 From: Joe4evr Date: Mon, 19 Mar 2018 11:33:57 +0100 Subject: [PATCH] Add BestMatch property to TypeReaderResult for easily accessing the parsed object --- src/Discord.Net.Commands/Results/TypeReaderResult.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Discord.Net.Commands/Results/TypeReaderResult.cs b/src/Discord.Net.Commands/Results/TypeReaderResult.cs index 68bc359c6..639ca3ac1 100644 --- a/src/Discord.Net.Commands/Results/TypeReaderResult.cs +++ b/src/Discord.Net.Commands/Results/TypeReaderResult.cs @@ -1,7 +1,8 @@ -using System; +using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Diagnostics; +using System.Linq; namespace Discord.Commands { @@ -30,6 +31,9 @@ namespace Discord.Commands public string ErrorReason { get; } public bool IsSuccess => !Error.HasValue; + public object BestMatch => IsSuccess + ? (Values.Count == 1 ? Values.Single().Value : Values.OrderByDescending(v => v.Score).First().Value) + : throw new InvalidOperationException("TypeReaderResult was not successful."); private TypeReaderResult(IReadOnlyCollection values, CommandError? error, string errorReason) {