nameOf()
the nameOf
function returns a String constant with the name of the passed identifier. Essentially, nameOf()
is a convenient way to reference a type's or type member's name without relying on manually coding a string literal that would not be checked by the compiler for typos.
method nameOf({ identifier or expression }): String;
string nameOf(/* identifier or expression */);
func nameOf(_ /* identifier or expression */) -> String
string nameOf(/* identifier or expression */);
Note: The function will return the shortest variation of the true platform-level name of the passed expression. For example, type names will exclude any namespace, and generic types or method names will be represented using the runtimelevel back-tick syntax. In C#, nameOf()
will preserve simple type keywords, so nameOf(int)
will return "int"
, while nameOf(System.Int32)
will return "Int32"
.