renderCopy static method

dynamic renderCopy(
  1. String clazz,
  2. List<SerField> fields
)

Implementation

static renderCopy(String clazz, List<SerField> fields) {
  if (fields.isEmpty) return '';
  final c = StringBuffer();
  final p = StringBuffer();
  final v = StringBuffer();
  for (final e in fields) {
    final id = e.id!.toCamelCase();
    c.writeln('/// * [$id] : ${e.did}');
    p.writeln('${e.type}? $id,');
    v.writeln('$id: $id ?? this.$id,');
  }
  return (LambdaContext _) => '''
    /// Types defined in Candid
    $c$clazz copyWith({
      $p
    }) {
      return $clazz($v);
    }
  ''';
}