Skip to content

Code Generators

Sieluna edited this page Jul 22, 2026 · 2 revisions

Code Generators

Sia.CodeGenerators is an analyzer project that removes repetitive component code. Reference it with OutputItemType="Analyzer" and ReferenceOutputAssembly="false".

Attribute Generates
[Sia] A SetXxx command/event and a writable component View property.
[SiaBundle] IStaticBundle conversion for a fixed component group.
[SiaEvents] An IEventUnion from nested event types.
[SiaTemplate] A component, constructor, reset command, property commands, and view from a template type.
[SiaSystem] An assembly system-descriptor provider.
[ReactiveComponent] A cached reactive component Definition; see Reactive.

Observable properties

public partial record struct Health([Sia] float Value);

var health = new Health.View(entity, world);
health.Value = 80;

The view assignment updates storage and sends Health.SetValue. A direct ref write remains silent.

Requirements

  • Types containing [Sia] members and reproduced containing types must be partial.
  • [SiaBundle], [SiaEvents], and [ReactiveComponent] targets must be partial.
  • [SiaTemplate] and [SiaSystem] targets need not be partial.
  • Bundle members need unique component types.
  • [SiaEvents] needs at least one public concrete nested IEvent.
  • [SiaSystem] targets must be classes implementing ISystem.
  • [ReactiveComponent] requires a static partial class, readonly record-struct props/state, a record message type, and valid InitialState, Reduce, and Render extension members.
  • Place [Sia], [SiaBundle], [SiaEvents], and [SiaTemplate] targets in a named namespace.
  • Avoid expression-bodied or init-only [Sia] properties, indexers, duplicate names, generic nested events, and nesting deeper than one containing type.

Use non-empty mutable templates. Immutable or empty templates currently omit a required static contract member.

Never edit .g.cs output. If generation fails, inspect the emitted file and fix the annotated source.

Clone this wiki locally