Skip to content

Commit

Permalink
Merge pull request #135 from pierre3/master
Browse files Browse the repository at this point in the history
fix IndexOutOfRangeException when ConsoleAppFilterAttribute is defined above CommandAttribute
  • Loading branch information
neuecc authored Jul 24, 2024
2 parents eb00116 + 1f5b765 commit 1761bb7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ConsoleAppFramework/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ internal class Parser(DiagnosticReporter context, InvocationExpressionSyntax nod
var commandAttribute = x.GetAttributes().FirstOrDefault(x => x.AttributeClass?.Name == "CommandAttribute");
if (commandAttribute != null)
{
commandName = (x.GetAttributes()[0].ConstructorArguments[0].Value as string)!;
commandName = (commandAttribute.ConstructorArguments[0].Value as string)!;
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,46 @@ public void Do()

verifier.Execute(code, "nomunomu", "yeah");
}
}

[Fact]
public void CommandAttrWithFilter()
{
var code = """
var builder = ConsoleApp.Create();
builder.Add<MyClass>();
builder.Run(args);
public class MyClass()
{
[ConsoleAppFilter<NopFilter1>]
[Command("nomunomu")]
[ConsoleAppFilter<NopFilter2>]
public void Do()
{
Console.Write("command");
}
}
internal class NopFilter1(ConsoleAppFilter next)
: ConsoleAppFilter(next)
{
public override Task InvokeAsync(ConsoleAppContext context,CancellationToken cancellationToken)
{
Console.Write("filter1-");
return Next.InvokeAsync(context, cancellationToken);
}
}
internal class NopFilter2(ConsoleAppFilter next)
: ConsoleAppFilter(next)
{
public override Task InvokeAsync(ConsoleAppContext context,CancellationToken cancellationToken)
{
Console.Write("filter2-");
return Next.InvokeAsync(context, cancellationToken);
}
}
""";

verifier.Execute(code, "nomunomu", "filter1-filter2-command");
}
}

0 comments on commit 1761bb7

Please sign in to comment.