Before I get started please be warned I'm new to Resharper and may well be overlooking something.
I'm attempting to use Resharper to automate some of my boiler plate code. In particular I want to automate copying of DI constructor parameters to private fields. I'm for the most part following the patterns in Microsoft's Razor Pages examples.
public class CreateModel : PageModel
{
private readonly AppDbContext _db;
public CreateModel(AppDbContext db)
{
_db = db;
}
}
Resharper does this, all good so far. But I also want to generate a throw on null propagation like so.
public class CreateModel : PageModel
{
private readonly AppDbContext _db;
public CreateModel(AppDbContext db)
{
_db = db ?? throw new ArgumentNullException(nameof(db));
}
}
I've tried looking at Resharper's Null Checking options, Templates Explorer, and every other option I can find that sounds relevant. But I can't seem to find any way to modify the behavior or create my own. Code snippets look right except they generate on the cursor. Wrap snippets don't seem right either.
So my question is, how can I create this behavior in Resharper (or plain old Visual Studio)?