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...
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...
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...
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 = ...
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 ...
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...
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...
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...
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.
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...
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...
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
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...
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);
...
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 = "...
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...
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
1 Next >
© 2022 - 2024 — McMap. All rights reserved.