From 70195bd9040f34c813bb425308f47011ec8e67b7 Mon Sep 17 00:00:00 2001 From: Dan Cojocaru Date: Mon, 20 Dec 2021 03:37:30 +0200 Subject: [PATCH] Generate constructors map as static --- bin/tdlib_gen.dart | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) 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 TdBase? fromJson(Map? 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? json) { + if (json == null) { + return null; + } + final type = json['@type'] as String; return constructors[type]!(json); } } -'''; +"""; return result; } String makeAbstractFile(TlSchema scheme) {