Analyzers
The Voltimax platform uses Roslyn incremental source generators to produce strongly-typed C# code at compile time from schema definitions. These generators live in projects conventionally named *.Analyzers - a .NET idiom where source generators ship alongside diagnostic analyzers in the same package type.
Generator Projects
| Project | Input | Generates |
|---|---|---|
| Contracts | JSON metric schemas, YAML device defs | Metric enums, catalogs, telemetry frames, device asset base classes |
| SunSpec | JSON SunSpec model specs | Typed SunSpec model classes with point metadata |
| Edge.Ocpp | OCPP 2.1 JSON schemas | Request/response message types, action registry |
| Edge.Control | YAML device definitions | Protocol-specific asset base classes (Modbus, HTTP, simulated) |
INFO
The Contracts and SunSpec generators are documented in detail below. The Edge generators (Ocpp, Control) are documented in the Edge Gateway section.
How It Works
All generators follow the same pattern:
- Schema files are included as
AdditionalFilesin the consuming project's.csproj - The Roslyn incremental generator reads these files during compilation
- Strongly-typed C# source is emitted into the compilation - no files on disk
- Any parsing errors surface as compiler diagnostics (see Diagnostics)
<!-- Example: wiring up metric schemas for source generation -->
<ItemGroup>
<PackageReference Include="Voltimax.Iot.Contracts.Analyzers"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="schemas/metrics/metrics.json" />
<AdditionalFiles Include="schemas/metrics/registries/*.json" />
</ItemGroup>The generated code becomes part of your compilation and is fully visible to IntelliSense. No CLI step, no pre-build script - just build.
Shared Infrastructure
All generator projects share:
- Target framework:
netstandard2.0(required for Roslyn analyzers) - Build props:
src/build/Voltimax.Analyzers.props- configures packaging, bundles dependencies as private assets - Common diagnostics: Identical
CommonDiagnosticDescriptors.cscopied into each project
Diagnostics
All generators report errors and warnings using the same diagnostic IDs:
| ID | Severity | Title | Description |
|---|---|---|---|
VGEN001 | Error | JSON parse error | The JSON file could not be parsed. Check that it is valid JSON and matches the expected schema. |
VGEN002 | Warning | YAML parse error | The YAML file could not be parsed. Check that it is valid YAML and matches the expected schema. |
VGEN003 | Warning | File not found | A referenced file could not be found. |
VGEN004 | Error | Generator error | An unexpected error occurred during code generation. |
VGEN005 | Warning | XML parse error | The XML file could not be parsed. Check that it is valid XML and matches the expected schema. |
These diagnostics appear in the Error List and build output like any other compiler diagnostic. They include the file path and a description of what went wrong.
Legacy CLI Generators
WARNING
The CLI-based generators in tools/Voltimax.Iot.Tools are the legacy approach. The Roslyn source generators documented here are the current mechanism for all code generation. The Schema section's Data Model reference remains valid for understanding the underlying schema formats.