Browse Source

Generate constructors map as static

master
Kenneth Bruen 3 years ago
parent
commit
70195bd904
Signed by: kbruen
GPG Key ID: C1980A470C3EE5B1
  1. 22
      bin/tdlib_gen.dart

22
bin/tdlib_gen.dart

@ -240,26 +240,28 @@ abstract class TdBase {
return 'td::TdBase()';
}
static TdBase? fromJson(Map<String, dynamic>? json) {
if (json == null) {
return null;
}
final type = json['@type'] as String;
final constructors = {
static final constructors = {
""";
for (final o in scheme.objects) {
final normName = o.name.pascalCase;
result += '''
'${o.name}': (json) => o.$normName.fromJson(json),
'${o.name}': (json) => o.$normName.fromJson(json),
''';
}
result += '''
};
result += """
};
static TdBase? fromJson(Map<String, dynamic>? json) {
if (json == null) {
return null;
}
final type = json['@type'] as String;
return constructors[type]!(json);
}
}
''';
""";
return result;
}
String makeAbstractFile(TlSchema scheme) {

Loading…
Cancel
Save