Implement missing members - add async when return type is Task?
Asked Answered
P

2

6

This question relates to ReSharper. If I have an interface that looks like this:

public interface IOrder {
    Task SetDeleted(Guid id);
}

and my class inherits from that interface, I would expect ReSharper to generate the following code, when selecting the "Implement missing members":

public class OrderService {
    public async Task SetDeleted(Guid id) {
        throw new NotImplementedException();
    }
}

However, it completely ignores the async part of the method, so I have to type that manually every single time. This was fixed in 2016.3 of ReSharper, as described here (at the bottom).

However, it does not work for the CTRL + . keybinding (or whatever it is), that looks like this:

enter image description here

Is it possible to somehow change, how this behavior works within ReSharper? I want all generated Task methods to be async automatically. There is no option within ReSharper's "Members Generation" that enables me to do this.

Pyromorphite answered 8/3, 2019 at 8:46 Comment(0)
L
6

In case class has only one missing member ReSharper doesn't show dialog therefore you can't tweak generation options. But you can add one more member to your interface and invoke generation action, this time ReSharper would show the dialog where you can set option "Make task-returning methods 'async'". This generation option is persistent i.e. it's last value will be stored in ReSharper settings and used by default.

Larceny answered 28/3, 2019 at 16:4 Comment(1)
You can use CTRL+SHIFT+I to open "insert missing members" dialog even with one member.Blotto
B
0

You can launch the Generate dialog even with one missing member by assigning a keyboard shortcut to the command ReSharper_GenerateImplementations:

enter image description here enter image description here

Baloney answered 29/7, 2024 at 7:26 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.