Skip to main content

Crate zerodds_idl_csharp

Crate zerodds_idl_csharp 

Source
Expand description

IDL4 → C# 12.0 source code generator (OMG IDL4-CSharp mapping, formal/2024-12-01).

Crate zerodds-idl-csharp — foundation of the language binding (cluster C5.3-a).

Safety classification: SAFE (std-only). Pure build-time tool — forbid(unsafe_code), no no_std use case.

§Scope (C5.3-a / phase 3.1-3.3)

  • Phase 3.1: header layout (#nullable enable, using, namespace).
  • Phase 3.2: primitive mapping (boolean → bool, octet → byte, char/wchar → char, short → short, ushort → ushort, long → int, ulong → uint, long long → long, ulong long → ulong, float/double, string → string).
  • Phase 3.3: aggregate types — struct → record class with init-only properties, enum → enum, union → discriminated record, typedef → record class wrapper (spec-compliant file-scoped using-alias arrives with C5.3-b), sequence → IList<T>, array → T[], inheritance → record class : Parent.

§C5.3-b additions (this revision)

  • ISequence<T> / IBoundedSequence<T> runtime contract (see runtime/Omg.Types.cs); codegen emits these instead of bare IList<T>.
  • Annotation-Bridge @key|@id|@optional|@must_understand|@external on members, @nested|@extensibility(...) on types — emitted as C# attributes from Omg.Types.
  • ITopicType<T> marker on every top-level (non-@nested) struct.

§Deliberately not in this crate

  • Phase 3.4: DDS-CSharp integration (P/Invoke to the Rust core).
  • Time/Duration/Status/QoS/Listener codegen.
  • File-scoped namespace + using <Alias> = <Type>; top-level form.
  • Bitset/Bitmask/Map/Fixed/Any/Interface/Valuetype.

§Example

use zerodds_idl::config::ParserConfig;
use zerodds_idl_csharp::{generate_csharp, CsGenOptions};

let ast = zerodds_idl::parse(
    "module M { struct S { long x; }; };",
    &ParserConfig::default(),
)
.expect("parse");
let cs = generate_csharp(&ast, &CsGenOptions::default()).expect("gen");
assert!(cs.contains("namespace M"));
assert!(cs.contains("record class S"));

Re-exports§

pub use error::CsGenError;

Modules§

emitter
AST walker that emits C# 12.0 source code.
error
Error types for the IDL → C# codegen.
keywords
C# reserved words and escaping logic.
type_map
Mapping IDL primitives → C# type strings.

Structs§

CsGenOptions
Configuration of the C# code generator.

Functions§

generate_csharp
Produces a complete C# 12.0 source text from an IDL specification.
generate_csharp_with_corba_traits
Convenience variant with the emit_corba_traits flag enabled.