writeClassDecode method
void
writeClassDecode(
- SwiftOptions generatorOptions,
- Root root,
- Indent indent,
- Class klass,
- Set<
String> customClassNames, - Set<
String> customEnumNames, { - required String dartPackageName,
override
Writes a single class decode method to indent
.
Implementation
@override
void writeClassDecode(
SwiftOptions generatorOptions,
Root root,
Indent indent,
Class klass,
Set<String> customClassNames,
Set<String> customEnumNames, {
required String dartPackageName,
}) {
final String className = klass.name;
indent.write('static func fromList(_ list: [Any?]) -> $className? ');
indent.addScoped('{', '}', () {
enumerate(getFieldsInSerializationOrder(klass),
(int index, final NamedType field) {
final String listValue = 'list[$index]';
_writeDecodeCasting(
root: root,
indent: indent,
value: listValue,
variableName: field.name,
type: field.type,
listEncodedClassNames: customClassNames,
listEncodedEnumNames: customEnumNames,
);
});
indent.newln();
indent.write('return ');
indent.addScoped('$className(', ')', () {
for (final NamedType field in getFieldsInSerializationOrder(klass)) {
final String comma =
getFieldsInSerializationOrder(klass).last == field ? '' : ',';
indent.writeln('${field.name}: ${field.name}$comma');
}
});
});
}