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

Reference / Enum

Enums

A fixed set of named values, used as a member type. By default an enum stores as a compact number; add [Type(string)] to store the member's own name instead — what you want when a human or another system reads the column. [Label] gives a member the human-readable label a screen shows. Three answers you will want before you open a page. (1) Room.Members is every member, in declaration order — `foreach (var r in Room.Members)` is how you build a picker, a tab bar or a filter; never hardcode the list, and Enum.GetValues<Room>() is the same array if you prefer C#'s spelling. (2) A member may be named for its own type: `[Required] Room Room;` compiles, exactly as `Color Color` does in C#. (3) Text(p.Room) renders the [Label] label, but "in " + p.Room concatenates the raw member NAME ("LivingRoom") — say p.Room.Label wherever a string is what you need. Full detail: osy docs enum-declaration#members and osy docs enum-labels#label-property.

stable2 examples compiled by CIenumguide

Summary#

An enum is a fixed set of named valuesenum Status { Draft, Placed, Cancelled } — used as the type of a member. It gives you a closed vocabulary the compiler checks: a value outside the set is a compile error, not a bad row. Two small decisions round it out: how it is stored (a number, or its name) and what a human sees (its label).

Description#

Declaring one#

An enum lists its members; any member or property can then take the enum as its type (an entity Order { Status Status; }, a function local, a component prop). The compiler enforces the set everywhere the enum is used, so a typo or a stale value is caught at compile time:

enum Status { Draft, Placed, Cancelled }
[Test]
void Status_is_a_fixed_set() {
  var s = Status.Placed;
  Assert.NotEqual(Status.Draft, s);
}

Stored as a number, or as its name#

By default an enum member is stored as a number — compact, and fine when only your own code reads it. When a human or another system will read the column, store it as the member's own name with [Type(string)], so the value in the database is "Placed" rather than 1. That is the setting to reach for on anything exported, reported on, or read by an integration. See enum.

The label a human reads#

A member's stored value is compact; the label on screen doesn't have to be. [Label], [Icon], [Tone] — what a human reads[Label("…")] — gives a member a human-readable label (the member's own name is the default), and a doc comment gives it a longer description. So InProgress can show as "In progress" without changing what is stored.

See also#

Related

enum

A fixed set of named values, used as a member type. Stored as a number by default, or as the member's own name with…

[Label], [Icon], [Tone] — what a human reads

An enum member stores a compact value but shows a human-readable label. [Label("…")] gives a member its label…

Types

The values your app computes with, and the declarations that name and scope them. Most scalar types are exactly C#'s —…

entity

Declares a persisted type — a table of rows the app stores, queries and secures. Every entity gets an Id and audit…