(
module: &ModuleDef,
output: &mut CodeIndenter<String>,
name: String,
product_type: &ProductTypeDef,
base: &str,
extra_body: impl FnOnce(&mut CodeIndenter<String>),
)
| 1444 | } |
| 1445 | |
| 1446 | fn autogen_csharp_product_common( |
| 1447 | module: &ModuleDef, |
| 1448 | output: &mut CodeIndenter<String>, |
| 1449 | name: String, |
| 1450 | product_type: &ProductTypeDef, |
| 1451 | base: &str, |
| 1452 | extra_body: impl FnOnce(&mut CodeIndenter<String>), |
| 1453 | ) { |
| 1454 | writeln!(output, "[SpacetimeDB.Type]"); |
| 1455 | writeln!(output, "[DataContract]"); |
| 1456 | write!(output, "public sealed partial class {name}"); |
| 1457 | if !base.is_empty() { |
| 1458 | write!(output, " : {base}"); |
| 1459 | } |
| 1460 | writeln!(output); |
| 1461 | indented_block(output, |output| { |
| 1462 | let fields = product_type |
| 1463 | .into_iter() |
| 1464 | .map(|(orig_name, ty)| { |
| 1465 | writeln!(output, "[DataMember(Name = \"{orig_name}\")]"); |
| 1466 | |
| 1467 | let field_name = orig_name.deref().to_case(Case::Pascal); |
| 1468 | let ty = ty_fmt(module, ty).to_string(); |
| 1469 | |
| 1470 | writeln!(output, "public {ty} {field_name};"); |
| 1471 | |
| 1472 | (field_name, ty) |
| 1473 | }) |
| 1474 | .collect::<Vec<_>>(); |
| 1475 | |
| 1476 | // If we don't have any fields, the default constructor is fine, otherwise we need to generate our own. |
| 1477 | if !fields.is_empty() { |
| 1478 | writeln!(output); |
| 1479 | |
| 1480 | // Generate fully-parameterized constructor. |
| 1481 | write!(output, "public {name}("); |
| 1482 | if fields.len() > 1 { |
| 1483 | writeln!(output); |
| 1484 | } |
| 1485 | { |
| 1486 | indent_scope!(output); |
| 1487 | for (i, (field_name, ty)) in fields.iter().enumerate() { |
| 1488 | if i != 0 { |
| 1489 | writeln!(output, ","); |
| 1490 | } |
| 1491 | write!(output, "{ty} {field_name}"); |
| 1492 | } |
| 1493 | } |
| 1494 | if fields.len() > 1 { |
| 1495 | writeln!(output); |
| 1496 | } |
| 1497 | writeln!(output, ")"); |
| 1498 | indented_block(output, |output| { |
| 1499 | for (field_name, _ty) in fields.iter() { |
| 1500 | writeln!(output, "this.{field_name} = {field_name};"); |
| 1501 | } |
| 1502 | }); |
| 1503 | writeln!(output); |
no test coverage detected
searching dependent graphs…