From a9d15543bbc9779f66a69ff0c889ea8c0c470ac0 Mon Sep 17 00:00:00 2001 From: hessenar Date: Thu, 30 Jun 2022 17:55:39 +0300 Subject: [PATCH 1/2] fix generate name value for MethodInfo without Parameters --- .../XmlDocReader.cs | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/System.CommandLine.DragonFruit/XmlDocReader.cs b/src/System.CommandLine.DragonFruit/XmlDocReader.cs index c5ce7322ee..227b30cb8c 100644 --- a/src/System.CommandLine.DragonFruit/XmlDocReader.cs +++ b/src/System.CommandLine.DragonFruit/XmlDocReader.cs @@ -55,26 +55,30 @@ public bool TryGetMethodDescription(MethodInfo info, out CommandHelpMetadata com sb.Append("M:"); AppendTypeName(sb, info.DeclaringType); sb.Append(".") - .Append(info.Name) - .Append("("); + .Append(info.Name); - bool first = true; - foreach (ParameterInfo param in info.GetParameters()) + var parameters = info.GetParameters(); + if (parameters.Length > 0) { - if (first) + sb.Append("("); + bool first = true; + foreach (ParameterInfo param in info.GetParameters()) { - first = false; - } - else - { - sb.Append(","); + if (first) + { + first = false; + } + else + { + sb.Append(","); + } + + AppendTypeName(sb, param.ParameterType); } - AppendTypeName(sb, param.ParameterType); + sb.Append(")"); } - sb.Append(")"); - string name = sb.ToString(); XElement member = _members.Elements("member") From 936bad2ac2ff4f17f25a212846fc592185c6759b Mon Sep 17 00:00:00 2001 From: hessenar Date: Sat, 2 Jul 2022 21:47:42 +0300 Subject: [PATCH 2/2] add test for XmlDocReader, case: method without input params --- .../XmlDocReaderTests.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/System.CommandLine.DragonFruit.Tests/XmlDocReaderTests.cs b/src/System.CommandLine.DragonFruit.Tests/XmlDocReaderTests.cs index 54369d864e..b9a862e612 100644 --- a/src/System.CommandLine.DragonFruit.Tests/XmlDocReaderTests.cs +++ b/src/System.CommandLine.DragonFruit.Tests/XmlDocReaderTests.cs @@ -15,6 +15,10 @@ private class Program public static void Main(bool verbose = false, string flavor = null, int? count = 0) { } + + public static void MainWithoutParam() + { + } } [Fact] @@ -47,5 +51,30 @@ public void It_finds_member_xml() helpMetadata.ParameterDescriptions["flavor"].Should().Be("Which flavor to use"); helpMetadata.ParameterDescriptions["count"].Should().Be("How many smoothies?"); } + + [Fact] + public void It_finds_member_without_param() + { + const string xml = @" + + + DragonFruit + + + + + Hello + + + + +"; + Action action = Program.MainWithoutParam; + var reader = new StringReader(xml); + XmlDocReader.TryLoad(reader, out var docReader).Should().BeTrue(); + + docReader.TryGetMethodDescription(action.Method, out var helpMetadata).Should().BeTrue(); + helpMetadata.Description.Should().Be("Hello"); + } } }