(module: &ModuleDef, sum_type_name: String, sum_type: &SumTypeDef, namespace: &str)
| 1379 | } |
| 1380 | |
| 1381 | fn 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 | |
| 1419 | fn autogen_csharp_plain_enum(enum_type_name: String, enum_type: &PlainEnumTypeDef, namespace: &str) -> String { |
| 1420 | let mut output = CsharpAutogen::new(namespace, &[], false); |
no test coverage detected
searching dependent graphs…