writeClassEncode method
void
writeClassEncode(
- DartOptions generatorOptions,
- Root root,
- Indent indent,
- Class classDefinition, {
- required String dartPackageName,
override
Writes a single class encode method to indent
.
Implementation
@override
void writeClassEncode(
DartOptions generatorOptions,
Root root,
Indent indent,
Class classDefinition, {
required String dartPackageName,
}) {
indent.write('Object encode() ');
indent.addScoped('{', '}', () {
indent.write(
'return <Object?>',
);
indent.addScoped('[', '];', () {
for (final NamedType field
in getFieldsInSerializationOrder(classDefinition)) {
final String conditional = field.type.isNullable ? '?' : '';
if (field.type.isEnum) {
indent.writeln(
'${field.name}$conditional.index,',
);
} else {
indent.writeln('${field.name},');
}
}
});
});
}