Don't write default value in help text for types that don't override ToString()

This commit is contained in:
Tyrrrz
2021-04-16 23:28:39 +03:00
parent 4835e64388
commit fc5af8dbbc
2 changed files with 8 additions and 5 deletions

View File

@@ -321,6 +321,8 @@ namespace CliFx.Formatting
Write(element.ToString(CultureInfo.InvariantCulture)); Write(element.ToString(CultureInfo.InvariantCulture));
Write(ConsoleColor.DarkGray, '"'); Write(ConsoleColor.DarkGray, '"');
} }
Write('.');
} }
} }
else else
@@ -332,10 +334,9 @@ namespace CliFx.Formatting
Write(ConsoleColor.DarkGray, '"'); Write(ConsoleColor.DarkGray, '"');
Write(defaultValue.ToString(CultureInfo.InvariantCulture)); Write(defaultValue.ToString(CultureInfo.InvariantCulture));
Write(ConsoleColor.DarkGray, '"'); Write(ConsoleColor.DarkGray, '"');
Write('.');
} }
} }
Write('.');
} }
} }

View File

@@ -54,9 +54,11 @@ namespace CliFx.Utils.Extensions
return array; return array;
} }
public static bool IsToStringOverriden(this Type type) => public static bool IsToStringOverriden(this Type type)
type.GetMethod(nameof(ToString), Type.EmptyTypes) != {
typeof(object).GetMethod(nameof(ToString), Type.EmptyTypes); var toStringMethod = type.GetMethod(nameof(ToString), Type.EmptyTypes);
return toStringMethod?.GetBaseDefinition()?.DeclaringType != toStringMethod?.DeclaringType;
}
// Types supported by `Convert.ChangeType(...)` // Types supported by `Convert.ChangeType(...)`
private static readonly HashSet<Type> ConvertibleTypes = new() private static readonly HashSet<Type> ConvertibleTypes = new()