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# – Exclude exception throw helper methods 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: One very useful application of the StackTraceHidden … Read more