Cysharp / ConsoleAppFramework

Zero Dependency, Zero Overhead, Zero Reflection, Zero Allocation, AOT Safe CLI Framework powered by C# Source Generator.
MIT License
1.54k stars 88 forks source link

More than 16 arguments when using a class method #110

Closed xPaw closed 1 month ago

xPaw commented 1 month ago

This works:

ConsoleApp.Run(args, (
    bool a1,
    bool a2,
    bool a3,
    bool a4,
    bool a5,
    bool a6,
    bool a7,
    bool a8,
    bool a9,
    bool a10,
    bool a11,
    bool a12,
    bool a13,
    bool a14,
    bool a15,
    bool a16,
    bool a17,
    bool a18,
    bool a19,
    string a20 = "test"
    ) => { });

But when doing the following, it fails to generate because Func<> does not accept more than 16 arguments (it doesn't generate a delegate like the anonymous lambda does).

Argument 2: cannot convert from 'method group' to 'System.Func'

public partial class Test
{
    public static void Main(string[] args)
    {
        var test = new Test();
        ConsoleApp.Run(args, test.Handle);
    }

    public void Handle(
        bool a1,
        bool a2,
        bool a3,
        bool a4,
        bool a5,
        bool a6,
        bool a7,
        bool a8,
        bool a9,
        bool a10,
        bool a11,
        bool a12,
        bool a13,
        bool a14,
        bool a15,
        bool a16,
        bool a17,
        bool a18,
        bool a19,
        string a20 = "test"
    )
    {
        //
    }
}

Side question: would it be possible to make it support class constructors, so that I could use readonly fields for options? For example: ConsoleApp.Run<Test>(args);

neuecc commented 1 month ago

Thank you. We already have a mechanism for generating delegate definitions, so if there are too many, will create custom delegate.