ReSharper
 
Get ReSharper
Get your hands on the new features ahead of the release by joining the Early Access Program for ReSharper 2025.1! Learn more

Code inspection: Redundant argument passed to caller argument expression parameter

Last modified: 27 August 2024

The [CallerArgumentExpression] attribute, introduced in C# 10, allows you to capture the string representation of the expression passed to a method parameter. This can be useful for logging, validation, or debugging purposes.

If you are using an API marked by this attribute, passing the string representation of the corresponding argument with another argument is not necessary. Therefore, ReSharper reports it as redundant and suggests removing it.

In the example below, the attribute is applied to the str parameter of the Write method. This means that if you call Write without specifying an argument for str, the compiler will automatically use the string representation of the expression provided for num. Since the argument "a + b" passed to str matches the string representation of the expression a + b passed to num, the second argument becomes redundant and can be safely removed.