From 40f174b22d4ceb93281a03414048c04598780170 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 27 Apr 2017 15:46:19 -0400 Subject: simplify exception summary code --- .../Framework/InternalExtensions.cs | 25 +++++++++++----------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'src/StardewModdingAPI/Framework') diff --git a/src/StardewModdingAPI/Framework/InternalExtensions.cs b/src/StardewModdingAPI/Framework/InternalExtensions.cs index 2f6f7490..5199c72d 100644 --- a/src/StardewModdingAPI/Framework/InternalExtensions.cs +++ b/src/StardewModdingAPI/Framework/InternalExtensions.cs @@ -92,21 +92,20 @@ namespace StardewModdingAPI.Framework /// The error to summarise. public static string GetLogSummary(this Exception exception) { - // type load exception - if (exception is TypeLoadException typeLoadEx) - return $"Failed loading type: {typeLoadEx.TypeName}: {exception}"; - - // reflection type load exception - if (exception is ReflectionTypeLoadException reflectionTypeLoadEx) + switch (exception) { - string summary = exception.ToString(); - foreach (Exception childEx in reflectionTypeLoadEx.LoaderExceptions) - summary += $"\n\n{childEx.GetLogSummary()}"; - return summary; - } + case TypeLoadException ex: + return $"Failed loading type '{ex.TypeName}': {exception}"; - // anything else - return exception.ToString(); + case ReflectionTypeLoadException ex: + string summary = exception.ToString(); + foreach (Exception childEx in ex.LoaderExceptions) + summary += $"\n\n{childEx.GetLogSummary()}"; + return summary; + + default: + return exception.ToString(); + } } /**** -- cgit