Brian Kessler
Brian Kessler

Reputation: 2327

In Visual Studio 2022, how can I change the null check template?

I frequently apply null checks to my parameters when developing in C# (like any good developer should!).

Because I can be lazy, I'd prefer to let Visual Studio add these for me, which it can.

However, when it adds the null checks, it consumes 4 lines of code per check. For example:

if (a is null)
{
    throw new ArgumentNullException(nameof(a));
}

That's ridiculous!

In an ideal world, it would just add a ! to the parameter name, some silly people canceled that feature, so I go for the second best option:

    _ = a ?? throw new ArgumentNullException(nameof(a));

Is there a way I can make Visual Studio 2022 work with me on this?

Upvotes: 0

Views: 724

Answers (0)

Related Questions