C # is the true operator name in D?

C # 6 has the "nameof" operator ( https://msdn.microsoft.com/library/dn986596.aspx ). Does D have an analogue? Or some kind of role model?

+6
source share
1 answer

I suppose stringof works the same way. For example, analog D with the first C # example in this link:

 void f(string s) { if (s == null) throw new Exception(s.stringof ~ " is null!"); } 

There is also std.traits.fullyQualifiedName . He does what he says on the bank:

 module mymodule; import std.traits : fullyQualifiedName; class MyClass { int myvar; } pragma(msg, MyClass.myvar.stringof); // myvar pragma(msg, fullyQualifiedName!(MyClass.myvar)); // mymodule.MyClass.myvar 

As you can see from the first link, fullyQualifiedName may be more suitable for generating compile-time code, where it helps to be as specific as possible in order to avoid collision with local characters.

+10
source

All Articles