MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / autogen_csharp_sum

Function autogen_csharp_sum

crates/codegen/src/csharp.rs:1381–1417  ·  view source on GitHub ↗
(module: &ModuleDef, sum_type_name: String, sum_type: &SumTypeDef, namespace: &str)

Source from the content-addressed store, hash-verified

1379}
1380
1381fn autogen_csharp_sum(module: &ModuleDef, sum_type_name: String, sum_type: &SumTypeDef, namespace: &str) -> String {
1382 let mut output = CsharpAutogen::new(namespace, &[], false);
1383
1384 writeln!(output, "[SpacetimeDB.Type]");
1385 write!(
1386 output,
1387 "public partial record {sum_type_name} : SpacetimeDB.TaggedEnum<("
1388 );
1389 {
1390 indent_scope!(output);
1391 for (i, (variant_name, variant_ty)) in sum_type.variants.iter().enumerate() {
1392 if i != 0 {
1393 write!(output, ",");
1394 }
1395 writeln!(output);
1396 let variant_name = variant_name.deref().to_case(Case::Pascal);
1397 write!(output, "{} {variant_name}", ty_fmt(module, variant_ty));
1398 }
1399 // If we have fewer than 2 variants, we need to add some dummy variants to make the tuple work.
1400 match sum_type.variants.len() {
1401 0 => {
1402 writeln!(output);
1403 writeln!(output, "SpacetimeDB.Unit _Reserved1,");
1404 write!(output, "SpacetimeDB.Unit _Reserved2");
1405 }
1406 1 => {
1407 writeln!(output, ",");
1408 write!(output, "SpacetimeDB.Unit _Reserved");
1409 }
1410 _ => {}
1411 }
1412 }
1413 writeln!(output);
1414 writeln!(output, ")>;");
1415
1416 output.into_inner()
1417}
1418
1419fn autogen_csharp_plain_enum(enum_type_name: String, enum_type: &PlainEnumTypeDef, namespace: &str) -> String {
1420 let mut output = CsharpAutogen::new(namespace, &[], false);

Callers 1

generate_type_filesMethod · 0.85

Calls 6

to_caseMethod · 0.80
iterMethod · 0.65
newFunction · 0.50
derefMethod · 0.45
lenMethod · 0.45
into_innerMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…