Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default arguments from a delegate definition are ignored. #453

Open
rgalex2034 opened this issue Jul 21, 2022 · 0 comments
Open

Default arguments from a delegate definition are ignored. #453

rgalex2034 opened this issue Jul 21, 2022 · 0 comments
Labels

Comments

@rgalex2034
Copy link

Hello,

I've noticed that when adding a delegate to a ScriptObject, it ignores the default arguments from the delegate definition and checks againts the arguments of the anonymous function/method used to create the delegate.

For example:

class SomeNewContext : ScriptObject
{
    public delegate void SomeDelegate(string text = "default");

    public SomeNewContext(SomeDelegate del)
    {
        this["scriban_function"] = del;
    }
}

In this case, it will ignore the default argument if I use something like new SomeNewContext(text => text.ToUpper()).

I've been checking why it happens and it's because it uses the delegate.Method to check against the arguments, and those may differ from the delegate.Invoke() call.
(https://github.com/scriban/scriban/blob/master/src/Scriban/Runtime/DelegateCustomFunction.cs#L27)

As a workaround I've found, wrapping the delegate on itself makes the delegate.Method return the signature of the delegate, like this: this["scriban_function"] = new SomeDelegate(del); in the example above.

@xoofx xoofx added the bug label Jul 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants