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"); + } } } 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")