tuple static method
Implementation
static Tuple4<String, String, String, String> tuple(
Iterable<SerField> sers, {
String? type,
bool nullable = false,
}) {
if (sers.isEmpty) {
return Tuple4('<dynamic>[[]]', '[]', 'List<dynamic>',
'IDL.Tuple(<CType<dynamic>>[],)');
}
final ser = StringBuffer();
final deser = StringBuffer();
final types = [];
final idl = [];
for (int i = 0; i < sers.length; ++i) {
final f = sers.elementAt(i);
types.add(f.type.nullable(f.nullable));
idl.add(f.idl);
final ind = i + 1;
final s = f.ser;
if (s != null) {
ser.write(s.replaceAll(ph, '$ph.item$ind'));
} else {
ser.write('$ph.item$ind');
}
ser.write(',');
final d = f.deser;
if (d != null) {
deser.write(d.replaceAll(ph, '$ph[$i]'));
} else {
deser.write('$ph[$i]');
}
deser.write(',');
}
final dartTypes = types.join(',');
final one = sers.length == 1;
if (one) {
final deserStr = deser.toString();
return Tuple4(
nullable ? '$ph==null?<dynamic>[]:<dynamic>[$ser]' : '<dynamic>[$ser]',
type == null
? deserStr.substring(0, deserStr.length - 1)
: '$type.fromList(<dynamic>[$deser],)',
type ?? dartTypes,
"IDL.Tuple(<CType<dynamic>>[${idl.join(",")}],)",
);
}
return Tuple4(
nullable ? '$ph==null?<dynamic>[]:<dynamic>[$ser]' : '<dynamic>[$ser]',
type == null
? 'Tuple${sers.length}<$dartTypes>.fromList(<dynamic>[$deser],)'
: '$type.fromList(<dynamic>[$deser],)',
type ?? (one ? dartTypes : 'Tuple${sers.length}<$dartTypes>'),
"IDL.Tuple(<CType<dynamic>>[${idl.join(",")}],)",
);
}