Generate constructors map as static
This commit is contained in:
parent
113808091e
commit
70195bd904
1 changed files with 14 additions and 12 deletions
|
@ -240,26 +240,28 @@ abstract class TdBase {
|
|||
return 'td::TdBase()';
|
||||
}
|
||||
|
||||
static final constructors = {
|
||||
""";
|
||||
|
||||
for (final o in scheme.objects) {
|
||||
final normName = o.name.pascalCase;
|
||||
result += '''
|
||||
'${o.name}': (json) => o.$normName.fromJson(json),
|
||||
''';
|
||||
}
|
||||
|
||||
result += """
|
||||
};
|
||||
|
||||
static TdBase? fromJson(Map<String, dynamic>? json) {
|
||||
if (json == null) {
|
||||
return null;
|
||||
}
|
||||
final type = json['@type'] as String;
|
||||
final constructors = {
|
||||
""";
|
||||
for (final o in scheme.objects) {
|
||||
final normName = o.name.pascalCase;
|
||||
result += '''
|
||||
'${o.name}': (json) => o.$normName.fromJson(json),
|
||||
''';
|
||||
}
|
||||
|
||||
result += '''
|
||||
};
|
||||
return constructors[type]!(json);
|
||||
}
|
||||
}
|
||||
''';
|
||||
""";
|
||||
return result;
|
||||
}
|
||||
String makeAbstractFile(TlSchema scheme) {
|
||||
|
|
Loading…
Add table
Reference in a new issue