Osy#the first language built for agents
Agents firstAgentic appsWorkflowsDurable Execution — built inSecurityTestingThe editorThe UI modelOne program

Reference / Function

nameof

nameof(symbol) → "symbol" (compile-time string fold)

The C# compile-time name fold: validates the symbol and folds to its simple-name string literal — the last identifier of the chain. Invalid symbols are compile errors. No runtime or stored surface.

stable1 example compiled by CIfunctionauthoring

Summary#

nameof(symbol) validates the symbol and folds — at compile time — to its simple-name string literal: the LAST identifier of the chain, exactly C#. There is no runtime or stored surface: the persisted node is an ordinary String literal (like const-inlining, the decompiled form shows the folded string).

Signature#

nameof(<name>)            // a local, param, entity set, or module
nameof(<Type>.<Member>)   // the type-member form → "Member"
nameof(<value>.<Member>)  // the value-member form → "Member"

Description#

Valid symbols, each folding to the last identifier:

  • a parameter or localnameof(count)"count";
  • an entity / type namenameof(Order)"Order"; a namespaced set folds to the simple name (nameof(osy.User)"User");
  • the type-member formnameof(Order.Total)"Total";
  • the value-member formnameof(o.Total)"Total" (the chain must resolve);
  • stdlib modulesnameof(Math)"Math".

Invalid symbols are compile errors, as in C#: nameof(missing)nameof: unknown symbol 'missing'; nameof(o.Nope)nameof: cannot resolve 'Nope' …; nameof(1 + 2)nameof requires a simple name or member access.

A local variable actually named nameof shadows the operator (C# contextual-keyword behavior).

Typical use: validation and error messages that survive renames.

Examples#

entity Order { decimal Total; }

string Examples(Order o, int count) {
  var total = 5;
  var a = nameof(count);        // "count"   — a parameter
  var b = nameof(total);        // "total"   — a local
  var c = nameof(Order);        // "Order"   — an entity name
  var d = nameof(Order.Total);  // "Total"   — the type-member form
  var e = nameof(o.Total);      // "Total"   — the value-member form
  return a + b + c + d + e;
}

See also#

  • const — the other compile-time fold (nameof stores exactly like an inlined const)

Related

const

A value fixed at compile time and folded into the places it is used. Declare one at the TOP LEVEL to share it across…

String interpolation & format specifiers

Build a string from literal text and embedded expressions with $"…{expr}…". A hole may carry a .NET format specifier…