Summary#
An enum member has three faces you can read in code from a value: value.Name is the member's identifier
("Placed"), value.Label is what a person reads (the [Label("…")] text, or the name when there is
none), and value.Description is the member's doc-comment sentence. They lower to the stdlib calls
Enum.Name, Enum.Label and Enum.Description.
Signature#
value.Name -> string // the member identifier, e.g. "Placed" (Enum.Name)
value.Label -> string // the [Label] label, else the name (Enum.Label)
value.Description -> string // the member's /// doc comment (Enum.Description)Description#
These read the words declared with the enum ([Label], [Icon], [Tone] — what a human reads): [Label("…")] sets the label, a ///
doc comment sets the description, and the member identifier is the name.
value.Labelis the display text. If the member has a[Label("…")], that is the label; otherwise the label falls back to the member name, because the name is usually already readable.value.Descriptionis the longer sentence from the member's doc comment — the help text under an option, for instance. A member with no doc comment has an empty description.value.Nameis always the raw identifier, ignoring any[Label].
You rarely need these for display. Showing an enum-typed value on a screen already renders its label for
you ([Label], [Icon], [Tone] — what a human reads) — reach for .Label/.Description/.Name when a function needs the words: building
a message, an export column, an audit line.
Because the words come from the app's model (which the client already has), these run in the browser with no round trip, just like the rest of the pure surface (execution side).
Examples#
enum OrderStatus {
/// The order is placed but has not shipped yet.
[Label("Awaiting shipment")] Placed,
Shipped,
}
// Build a one-line status message from the words, not the stored value.
string StatusLine(OrderStatus s) {
return s.Label + " — " + s.Description;
}[Test]
void Enum_words() {
// a member WITH a [Label] and a doc comment
Assert.Equal("Placed", OrderStatus.Placed.Name); // the identifier
Assert.Equal("Awaiting shipment", OrderStatus.Placed.Label); // the [Label] text
Assert.Equal("The order is placed but has not shipped yet.", OrderStatus.Placed.Description);
// a member WITHOUT a [Label]: the label falls back to the name
Assert.Equal("Shipped", OrderStatus.Shipped.Name);
Assert.Equal("Shipped", OrderStatus.Shipped.Label); // no [Label] → the name
Assert.Equal("Awaiting shipment — The order is placed but has not shipped yet.",
StatusLine(OrderStatus.Placed));
}See also#
- [Label], [Icon], [Tone] — what a human reads — declaring the
[Label]label and the doc-comment description these read - enum — the
enumkeyword and how a member is stored - switch — branching on an enum value