# Sandbox.CodeGenerator

Generates C# source from in-memory .cs, declaration-only .csx and .razor files using the addon generators.
Does not emit assemblies, execute code or perform sandbox access validation.
Configure on one thread; each generation snapshots its inputs before starting background work.

- Kind: class
- Namespace: `Sandbox`
- Assembly: `Sandbox.Compiling`
- Modifiers: sealed

## Constructors

- [`CodeGenerator`](/api/Sandbox.CodeGenerator/.ctor)

## Properties

- [`AssemblyName`](/api/Sandbox.CodeGenerator/AssemblyName): The assembly identity used for semantic analysis and generated metadata.
- [`Defines`](/api/Sandbox.CodeGenerator/Defines): Preprocessor symbols used when parsing the input files.
- [`GlobalUsings`](/api/Sandbox.CodeGenerator/GlobalUsings): Namespaces imported by every file. Imports are included in the output source set.
- [`RootNamespace`](/api/Sandbox.CodeGenerator/RootNamespace): Root namespace used by Razor, followed by the source file's folders.

## Methods

- [`AddFile`](/api/Sandbox.CodeGenerator/AddFile): Adds or replaces source at a project-relative path. No file is read from disk.
- [`AddReference`](/api/Sandbox.CodeGenerator/AddReference): Adds a metadata reference for semantic analysis. References are supplied by the caller, not discovered globally.
- [`ClearFiles`](/api/Sandbox.CodeGenerator/ClearFiles): Removes all input files, retaining references and settings. Already-started generations keep their snapshots.
- [`GenerateAsync`](/api/Sandbox.CodeGenerator/GenerateAsync): Generates a complete source set from a snapshot of the current inputs, retaining the original inputs for later calls. Cancellation is observed between generation stages; an active generator pass may finish before cancellation is observed.
- [`RemoveFile`](/api/Sandbox.CodeGenerator/RemoveFile): Removes an input file, returning whether it was present.
