Code inspection: Redundant argument passed to caller argument expression parameter
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, JetBrains Rider 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.