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

Add better support for delegate arguments #66

Closed
maca88 opened this issue Nov 3, 2017 · 3 comments
Closed

Add better support for delegate arguments #66

maca88 opened this issue Nov 3, 2017 · 3 comments
Milestone

Comments

@maca88
Copy link
Owner

maca88 commented Nov 3, 2017

Example:

public class MethodWithDelegate
{
    public void Test()
    {
        Read(() => SimpleFile.Read());
    }

    public void Read(Action action)
    {
        action();
        SimpleFile.Read();
    }
}

Expected result

public partial class MethodWithDelegate
{
    public Task TestAsync()
    {
        return ReadAsync(() => SimpleFile.Read());
    }

    public Task ReadAsync(Action action)
    {
        try
        {
            action();
            return SimpleFile.ReadAsync();
        }
        catch (Exception ex)
        {
            return Task.FromException<object>(ex);
        }
    }
}

Actual result

public partial class MethodWithDelegate
{

    public Task ReadAsync(Action action)
    {
        try
        {
            action();
            return SimpleFile.ReadAsync();
        }
        catch (Exception ex)
        {
            return Task.FromException<object>(ex);
        }
    }
}
@maca88 maca88 closed this as completed in 6bfbe3e Nov 4, 2017
@maca88 maca88 added this to the 0.6.0 milestone Nov 5, 2017
@hazzik
Copy link
Contributor

hazzik commented Nov 7, 2017

In some circumstances, I would expect to have async lambda as an argument (when it is convertible to async)

public partial class MethodWithDelegate
{
    public Task TestAsync()
    {
        // In this case async-await is optional
        return ReadAsync(async () => await SimpleFile.ReadAsync());
    }

    public Task ReadAsync(Func<Task> actionAsync)
    {
        await actionAsync();
        return SimpleFile.ReadAsync();
    }
}

@maca88
Copy link
Owner Author

maca88 commented Nov 7, 2017

I've opened a separate issue for this one.

@hazzik
Copy link
Contributor

hazzik commented Nov 7, 2017

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants