Skip to content

Please provide a Source Generator that generates an implementation of ICommandHandler. #1980

@aetos382

Description

@aetos382

I would like a Source Generator that supports implementing ICommandHandler like DragonFruit.

For example, for the following code,

partial class CommandHandler
{
    [CommandHandler]
    Task<int> Handle(
        int foo)
    {
        // command handling
    }
}

generates following implementation.

partial class CommandHandler : ICommandHandler
{
    public Task<int> InvokeAsync(InvocationContext context)
    {
        var fooOption = context.ParseResult.CommandResult.Command.Options
            .SingleOrDefault(static option => option.Name == "foo");

        var fooValue = context.ParseResult.GetValueForOption(fooOption);

        return this.Handle(fooValue);
    }
}

The above code is for a very simple case; more considerations are needed for what actually works.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions