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

C# – Hide a method from the stack trace

When you want to exclude a method from showing up in the stack trace, you can apply the StackTraceHidden attribute to the method: Note: This attribute was added in .NET 6. You can apply StackTraceHidden to a class to hide all of its methods from the stack trace: Use StackTraceHidden with throw helper methods StackTraceHidden … Read more