In C#, `nameof` expressions are a form of reflection. They return the string representation of the argument, as seen by the compiler.
Questions tagged [nameof]
100 questions
0
votes
2 answers
Pass property as function argument and convert it name to string inside
I would like to be able to pass any possible type as function parameter.
Now, there is problem with passing property eg.
class Foo
{
public int Bar { get; set; }
}
I'm able to use:
nameof(Foo.Bar)
but I'm unable to do A(Foo.Bar) where in A will…

senfen
- 877
- 5
- 21
0
votes
2 answers
C# - take method as an argument without specifying args
I have a method that needs to take the function and its owner class as the input arguments and then to proceed with its names with reflection. Of course I could take a couple of strings as the input args, so the method would look like this:
void…

bashis
- 1,200
- 1
- 16
- 35
0
votes
1 answer
Deny use of nameof as parameter of method
I have this C# function:
public void MyFunction(string propertyName)
{
....
}
The function stores the property name in a database for further use.
I want to prevent the users of this method to use nameof(MyProperty) as a parameter, to prevent…

aengas
- 155
- 12
0
votes
1 answer
Is it possible to get the original parameter name using nameof() in a lambda expression?
I need to create a CSV style string of parameters mapped to their values.
For example:
static void MyMethod(int i, string str, object obj, bool flag)
{
string example = "i=123,str=Hello,obj=1.0,flag=false";
}
Called like:
MyMethod(123, "Hello",…

TVOHM
- 2,740
- 1
- 19
- 29
-1
votes
1 answer
nameof() operator for Multiple Levels of Properties
What is nameof() equivalent for the following expression:
query.Include(x => x.Collection.Select(y => y.Property))

roozbeh S
- 1,084
- 1
- 9
- 16
-1
votes
2 answers
Passing main methods arrays with their original names to another method
So I have made a simple code, which passes two different arrays to a method, to check for Exceptions. But there is one problem - when I pass the arrays, if an exception is cached, in my Exceptions "nameof" part, it doesn't say which array was the…

Ričards Mauriņš
- 13
- 4
-1
votes
1 answer
Why doesn't nameof work on synonymous?
From this question I learned that the nameof() operator, introduced in C# 6.0, does not work on synonymous. So you can write nameof(System.Object) but not nameof(object).
Now, there are 2 other similar operators, typeof() and default(), and they…

Massimiliano Kraus
- 3,638
- 5
- 27
- 47
-1
votes
1 answer
Is there a way to get name of an argument from calling method in called method?
The following code prints "argument".
void PrintNameOf(string argument)
{
Console.WriteLine($"{nameof(argument)} has value: {argument}");
}
string myString = "hello";
PrintNameOf(myString);
Is there a way to get "myString"?

Corio
- 395
- 7
- 20
-2
votes
2 answers
Xamarin.Forms - Difference between Label.TextProperty.PropertyName and nameof(myLabel.Text)
Besides the syntax, is there any difference between:
Label.TextProperty.PropertyName //(Xamarin.Forms.BindableProperty.PropertyName)
and
nameof(myLabel.Text)
?

jbyrd
- 5,287
- 7
- 52
- 86
-4
votes
1 answer
SQL Equivalent to `nameof` operator in C#, Java, etc
Is there an equivalent to the nameof operator in languages like C#, Java, etc for any SQL database implementations, in particular SQL Server?
If not, is there an equivalent function that can be rolled that will pass back a string (VARCHAR, etc) of a…

LSM07
- 787
- 2
- 7
- 21