diff --git a/bin/tdlib_gen.dart b/bin/tdlib_gen.dart index 1bb42dc..78ee759 100644 --- a/bin/tdlib_gen.dart +++ b/bin/tdlib_gen.dart @@ -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? 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) {