Skip to content

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

ProjectInputGenerates
ContractsJSON metric schemas, YAML device defsMetric enums, catalogs, telemetry frames, device asset base classes
SunSpecJSON SunSpec model specsTyped SunSpec model classes with point metadata
Edge.OcppOCPP 2.1 JSON schemasRequest/response message types, action registry
Edge.ControlYAML device definitionsProtocol-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:

  1. Schema files are included as AdditionalFiles in the consuming project's .csproj
  2. The Roslyn incremental generator reads these files during compilation
  3. Strongly-typed C# source is emitted into the compilation - no files on disk
  4. Any parsing errors surface as compiler diagnostics (see Diagnostics)
xml
<!-- 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.cs copied into each project

Diagnostics

All generators report errors and warnings using the same diagnostic IDs:

IDSeverityTitleDescription
VGEN001ErrorJSON parse errorThe JSON file could not be parsed. Check that it is valid JSON and matches the expected schema.
VGEN002WarningYAML parse errorThe YAML file could not be parsed. Check that it is valid YAML and matches the expected schema.
VGEN003WarningFile not foundA referenced file could not be found.
VGEN004ErrorGenerator errorAn unexpected error occurred during code generation.
VGEN005WarningXML parse errorThe 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.