nameof Questions

7

Solved

C# 6.0 introduced the nameof() operator, that returns a string representing the name of any class / function / method / local-variable / property identifier put inside it. If I have a class like t...
Garlen asked 28/11, 2016 at 18:18

6

nameof(order.User.Age) return only Age instead of order.User.Age What is the reason to do it in more restricted way? If we want only last name we could do something like public static GetLastNam...
Minni asked 12/1, 2015 at 8:50

4

Solved

Assume I have the type public class A<T> { } and somewhere in the code I want to throw an exception related to incorrect usage of that type: throw new InvalidOperationException("Cannot us...
Delwin asked 18/4, 2018 at 11:0

3

Scenario I have a class for declaring string constants used around a program: public static class StringConstants { public const string ConstantA = "ConstantA"; public const string ConstantB = ...
Thaddeusthaddus asked 30/11, 2016 at 12:43

9

Is there a recommended way to use the new nameof() expression in ASP.NET MVC for controller names? Url.Action("ActionName", "Home") <------ works vs Url.Action(nameof(ActionName), nameof...
Chavey asked 12/12, 2014 at 12:54

2

Solved

I'm trying to get the full name of a namespace and convert it to a string. Specifically, I have the namespace DevExpress.Xpf and I would like nameof2(DevExpress.Xpf) or some equivalent to return &q...
Langdon asked 25/3, 2022 at 13:27

2

Imagine a type at the root namespace level (could be in the default global space, or could potentially be an extern alias). It appears that this type cannot be referred to via nameof(), when using ...
Lactic asked 9/9, 2021 at 10:34

3

Solved

I would like to validate multiple parameters and throw an ArgumentNullException if any of them are null. For the sake of argument, let's assume I've got this: public void DoSomething(SomeClass par...
Delirious asked 6/3, 2019 at 0:4

17

Solved

Version 6.0 got a new feature of nameof, but I can't understand the purpose of it, as it just takes the variable name and changes it to a string on compilation. I thought it might have some purpos...
Lindblad asked 29/7, 2015 at 9:4

2

Ok, there's an existing question here on S/O with the following title: Swift: Get Variable Actual Name as String By it's name, it seems that's exactly what I want. However, looking at the accepted ...
Nicolina asked 19/12, 2017 at 16:34

1

Solved

I'm trying to use the new nameof feature in F# 5.0 preview. It works for values but not for record properties, e.g.: type MyType { Id: int } let name = nameof MyType.Id This results in the error F...
Tina asked 9/1, 2021 at 21:14

2

With reference to Is there an equivalent of C#'s nameof(..) in F#? how can the nameof function used or extended for the following case? let nameof (q:Expr<_>) = match q with | Pattern...
Quoit asked 3/12, 2020 at 3:0

1

Solved

I'm using F# 4.7 with <LangVersion>preview</LangVersion> in my project file. I have a type like this: type Record = { Name : string Description : string FieldNotInterestedIn: int } ...
Silverman asked 20/7, 2020 at 19:6

5

Solved

"nameof" expression is introduced in Visual Studio 2015 and c# 6 nameof (C# and Visual Basic Reference) How can u use it or write a similar method in older versions like .net framework 4.
Melodramatic asked 7/7, 2015 at 7:6

4

Solved

Have browsed, searched and hoped but cannot find a straight answer. Is there anyway in C# 6.0 to get the current method name using nameof withouth specifying the method name? I am adding my test ...
Alberich asked 29/6, 2016 at 11:52

3

Solved

I'm a little bit confused with nameof() operator. So for example I can't use class's private fields in nameof() in another class, but I can use public non static fields using non static property, s...
Gauge asked 21/6, 2018 at 9:3

5

I'd like to use the following C#6 code var joe = new Self(); Console.WriteLine(joe); ... and get the following output: joe The following attempt class Self { public string Name { get; se...
Miranda asked 8/1, 2015 at 10:26

1

Solved

Is it possible to get the name of class's property (attention!) at compile time and without object instantiation? With instantiation it can easely be done with nameof(): class DummyClass { publi...
Chaldean asked 17/5, 2018 at 12:8

7

Solved

Correct me if I am wrong, but doing something like var typeOfName = typeof(Foo).Name; and var nameOfName = nameof(Foo); should give you exactly the same output. One of the understandable rea...
Unblessed asked 11/11, 2015 at 11:23

2

Solved

I regularly want to get the name of an instance property of a type, when I have no instance. Currently to do this, I use the following inhouse function which interprets the Expression[Func[T, objec...
Marna asked 8/7, 2016 at 2:2

1

Solved

In C# 6.0 you can write this: var instance = default(object); var type = typeof(object); They have the same result of: var instance = default(System.Object); var type = typeof(System.Object); ...
Dominy asked 4/11, 2016 at 11:49

1

Solved

I thought I could make use of the new c# 6 operator nameof to build a dictionary of key/values implicitly from a params array. As an example, consider the following method call: string myName = "...
Wiry asked 3/11, 2016 at 13:53

2

Solved

I'm trying to do something with nameof expressions in a CSharpSyntaxWalker, however, I noticed that there is no NameOfExpressionSyntax in the AST. Instead I get an InvocationExpressionSyntax for wh...
Caldarium asked 5/9, 2016 at 7:22

4

Solved

It is a good idea to use nameof over expressions for extracting property names? //method with expression protected void RaisePropertyChanged<T>(Expression<Func<T>> propertyExpres...
Epigenous asked 12/7, 2016 at 8:57

2

Solved

In relation to the question Get the name of parameters from a calling method and Finding the Variable Name passed to a Function in C# I'm still looking for a way to define theWhatDoesTheAnimalSay_W...
Glorianna asked 5/6, 2016 at 7:5

© 2022 - 2024 — McMap. All rights reserved.