From fc5af8dbbc627af207f96ab055672af18520521e Mon Sep 17 00:00:00 2001 From: Tyrrrz Date: Fri, 16 Apr 2021 23:28:39 +0300 Subject: [PATCH] Don't write default value in help text for types that don't override ToString() --- CliFx/Formatting/HelpConsoleFormatter.cs | 5 +++-- CliFx/Utils/Extensions/TypeExtensions.cs | 8 +++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CliFx/Formatting/HelpConsoleFormatter.cs b/CliFx/Formatting/HelpConsoleFormatter.cs index d691cfc..0432077 100644 --- a/CliFx/Formatting/HelpConsoleFormatter.cs +++ b/CliFx/Formatting/HelpConsoleFormatter.cs @@ -321,6 +321,8 @@ namespace CliFx.Formatting Write(element.ToString(CultureInfo.InvariantCulture)); Write(ConsoleColor.DarkGray, '"'); } + + Write('.'); } } else @@ -332,10 +334,9 @@ namespace CliFx.Formatting Write(ConsoleColor.DarkGray, '"'); Write(defaultValue.ToString(CultureInfo.InvariantCulture)); Write(ConsoleColor.DarkGray, '"'); + Write('.'); } } - - Write('.'); } } diff --git a/CliFx/Utils/Extensions/TypeExtensions.cs b/CliFx/Utils/Extensions/TypeExtensions.cs index 03be3db..8916965 100644 --- a/CliFx/Utils/Extensions/TypeExtensions.cs +++ b/CliFx/Utils/Extensions/TypeExtensions.cs @@ -54,9 +54,11 @@ namespace CliFx.Utils.Extensions return array; } - public static bool IsToStringOverriden(this Type type) => - type.GetMethod(nameof(ToString), Type.EmptyTypes) != - typeof(object).GetMethod(nameof(ToString), Type.EmptyTypes); + public static bool IsToStringOverriden(this Type type) + { + var toStringMethod = type.GetMethod(nameof(ToString), Type.EmptyTypes); + return toStringMethod?.GetBaseDefinition()?.DeclaringType != toStringMethod?.DeclaringType; + } // Types supported by `Convert.ChangeType(...)` private static readonly HashSet ConvertibleTypes = new()