C# – Get argument names automatically

You can use the CallerArgumentExpression attribute to automatically get the name of an argument being passed into a method: Note: CallerArgumentExpression was added in .NET 6. Here’s an example to show what CallerArgumentExpression does: Calling this method outputs the following: You use the CallerArgumentExpression attribute with a default string parameter (i.e. string argumentName = null). … Read more