From 0e4cee7ce10d2a9a544ddf4b7e988192ea411560 Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Thu, 30 Mar 2023 15:21:03 +0200 Subject: [PATCH 1/2] address code review feedback --- src/System.CommandLine/Argument{T}.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/System.CommandLine/Argument{T}.cs b/src/System.CommandLine/Argument{T}.cs index acc27e8aec..269da60b37 100644 --- a/src/System.CommandLine/Argument{T}.cs +++ b/src/System.CommandLine/Argument{T}.cs @@ -169,11 +169,15 @@ public void AcceptLegalFileNamesOnly() { if (default(T) is null && typeof(T) != typeof(string)) { - if (typeof(T).IsArray) +#if NET7_0_OR_GREATER + if (typeof(T).IsSZArray) +#else + if (typeof(T).IsArray && typeof(T).GetArrayRank() == 1) +#endif { return (T?)(object)Array.CreateInstance(typeof(T).GetElementType()!, 0); } - else if (typeof(T).IsGenericType) + else if (typeof(T).IsConstructedGenericType) { var genericTypeDefinition = typeof(T).GetGenericTypeDefinition(); From 75645273894946695ab171df152d28c7b0eedf43 Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Thu, 30 Mar 2023 15:28:05 +0200 Subject: [PATCH 2/2] merge HelpBuilderExtensions into HelpBuilder --- ...CommandLine_api_is_not_changed.approved.txt | 5 ++--- .../Help/HelpBuilderExtensions.cs | 18 +++++------------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt b/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt index dea633f471..3b31cc7dca 100644 --- a/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt +++ b/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt @@ -187,8 +187,10 @@ System.CommandLine.Help public System.Int32 MaxWidth { get; } public System.Void CustomizeLayout(System.Func>> getLayout) public System.Void CustomizeSymbol(System.CommandLine.Symbol symbol, System.Func firstColumnText = null, System.Func secondColumnText = null, System.Func defaultValue = null) + public System.Void CustomizeSymbol(System.CommandLine.Symbol symbol, System.String firstColumnText = null, System.String secondColumnText = null, System.String defaultValue = null) public TwoColumnHelpRow GetTwoColumnRow(System.CommandLine.Symbol symbol, HelpContext context) public System.Void Write(HelpContext context) + public System.Void Write(System.CommandLine.Command command, System.IO.TextWriter writer) public System.Void WriteColumns(System.Collections.Generic.IReadOnlyList items, HelpContext context) static class Default public static System.Action AdditionalArgumentsSection() @@ -203,9 +205,6 @@ System.CommandLine.Help public static System.Action OptionsSection() public static System.Action SubcommandsSection() public static System.Action SynopsisSection() - public static class HelpBuilderExtensions - public static System.Void CustomizeSymbol(this HelpBuilder builder, System.CommandLine.Symbol symbol, System.String firstColumnText = null, System.String secondColumnText = null, System.String defaultValue = null) - public static System.Void Write(this HelpBuilder helpBuilder, System.CommandLine.Command command, System.IO.TextWriter writer) public class HelpContext .ctor(HelpBuilder helpBuilder, System.CommandLine.Command command, System.IO.TextWriter output, System.CommandLine.ParseResult parseResult = null) public System.CommandLine.Command Command { get; } diff --git a/src/System.CommandLine/Help/HelpBuilderExtensions.cs b/src/System.CommandLine/Help/HelpBuilderExtensions.cs index 9d7a5272a6..992119a375 100644 --- a/src/System.CommandLine/Help/HelpBuilderExtensions.cs +++ b/src/System.CommandLine/Help/HelpBuilderExtensions.cs @@ -5,38 +5,30 @@ namespace System.CommandLine.Help { - /// - /// Provides extension methods for the help builder. - /// - public static class HelpBuilderExtensions + public partial class HelpBuilder { /// /// Specifies custom help details for a specific symbol. /// - /// The help builder to write with. /// The symbol to customize the help details for. /// A delegate to display the first help column (typically name and usage information). /// A delegate to display second help column (typically the description). /// The displayed default value for the symbol. - public static void CustomizeSymbol( - this HelpBuilder builder, + public void CustomizeSymbol( Symbol symbol, string? firstColumnText = null, string? secondColumnText = null, string? defaultValue = null) { - builder.CustomizeSymbol(symbol, _ => firstColumnText, _ => secondColumnText, _ => defaultValue); + CustomizeSymbol(symbol, _ => firstColumnText, _ => secondColumnText, _ => defaultValue); } /// /// Writes help output for the specified command. /// - public static void Write( - this HelpBuilder helpBuilder, - Command command, - TextWriter writer) + public void Write(Command command, TextWriter writer) { - helpBuilder.Write(new HelpContext(helpBuilder, command, writer)); + Write(new HelpContext(this, command, writer)); } } } \ No newline at end of file