nameof(@object) == "@object" while [CallerArgumentExpression] injects "object" #7224
Replies: 3 comments 5 replies
-
Can you provide a clearer repro that includes all referencedd symbols. I have no idea where |
Beta Was this translation helpful? Give feedback.
2 replies
-
This? using System;
using System.Runtime.CompilerServices;
object @object = "foo";
M(nameof(@object));
void M(string x, [CallerArgumentExpression("x")] string? y = null) {
Console.WriteLine(x); // prints "object"
Console.WriteLine(y); // prints "nameof(@object)"
} |
Beta Was this translation helpful? Give feedback.
3 replies
-
@HaloFour Yes, it's my case: using System;
namespace CallerArgumentExpressionVsNameoff
{
internal class Program
{
internal static void Main(string[] args)
{
object @object = "foo";
M(nameof(@object));
}
private static void M(object x, [CallerArgumentExpression("x")] string? y = null)
{
Console.WriteLine(x); // prints "object"
Console.WriteLine(y); // prints "nameof(@object)"
}
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I'd like to believe it's .net runtime issue but would like to check here first, maybe it's language specific.
Here is how I found this subtle difference: r-pankevicius/EnsureArg6@9fc6856
/r
PS: The method under test (with CallerArgumentExpressionAttribute) is:
https://github.com/r-pankevicius/EnsureArg6/blob/main/src/EnsureArg6/EnsureArg6.Types.cs#L92
Beta Was this translation helpful? Give feedback.
All reactions