Browse Source

Update FromJson

Felix 2 years ago
parent
commit
46dc05ff09
1 changed files with 13 additions and 9 deletions
  1. 13 9
      ModeType.cs

+ 13 - 9
ModeType.cs

@@ -346,39 +346,43 @@ namespace FlutterCodeGenerator
                     var argumentName2 = dictionaryModelType.GenericArgumentModelTypeList[1].GetFlutterTypeName();
                     source.AppendLine($"\t\t\t{child.Name_Lower}: map['{child.Name_Upper}'] != null ? map['{child.Name_Upper}'].cast<{argumentName1},{argumentName2}>() : null,");
                 }
-                else if (child is UserDefinedGenericModelType userDefinedGenericComplexModelType)
+                else if (child is UserDefinedGenericModelType userDefinedGenericModelType)
                 {
                     if (this is UserDefinedGenericModelType type)
                     {
-                        if (type.GenericArgumentModelType.ParameterType == userDefinedGenericComplexModelType.GenericArgumentModelType.ParameterType)
+                        if (type.GenericArgumentModelType.ParameterType == userDefinedGenericModelType.GenericArgumentModelType.ParameterType)
                         {
-                            source.AppendLine($"\t\t\t{child.Name_Lower}: {userDefinedGenericComplexModelType.Name_Lower}List,");
+                            source.AppendLine($"\t\t\t{child.Name_Lower}: {userDefinedGenericModelType.Name_Lower}List,");
                         }
-                        else if (userDefinedGenericComplexModelType.GenericArgumentModelType is SimpleModelType)
+                        else if (userDefinedGenericModelType.GenericArgumentModelType is SimpleModelType)
                         {
-                            var model = userDefinedGenericComplexModelType.GenericArgumentModelType.GetFlutterTypeName();
+                            var model = userDefinedGenericModelType.GenericArgumentModelType.GetFlutterTypeName();
                             source.AppendLine($"\t\t\t{child.Name_Lower}: map['{child.Name_Upper}'] != null ? map['{child.Name_Upper}'].cast<{model}>().toList() : null,");
                         }
                         else
                         {
-                            var model = userDefinedGenericComplexModelType.GenericArgumentModelType.GetFlutterTypeName();
+                            var model = userDefinedGenericModelType.GenericArgumentModelType.GetFlutterTypeName();
                             source.AppendLine($"\t\t\t{child.Name_Lower}: map['{child.Name_Upper}'] != null ? (map['{child.Name_Upper}'] as List).map((e)=>{model}.fromJson(e as Map<String,dynamic>)).toList() : null,");
                         }
                     }
                     else if (this is UserDefinedModeType)
                     {
-                        if (userDefinedGenericComplexModelType.GenericArgumentModelType is SimpleModelType)
+                        if (userDefinedGenericModelType.GenericArgumentModelType is SimpleModelType)
                         {
-                            var model = userDefinedGenericComplexModelType.GenericArgumentModelType.GetFlutterTypeName();
+                            var model = userDefinedGenericModelType.GenericArgumentModelType.GetFlutterTypeName();
                             source.AppendLine($"\t\t\t{child.Name_Lower}: map['{child.Name_Upper}'] != null ? map['{child.Name_Upper}'].cast<{model}>().toList() : null,");
                         }
                         else
                         {
-                            var model = userDefinedGenericComplexModelType.GenericArgumentModelType.GetFlutterTypeName();
+                            var model = userDefinedGenericModelType.GenericArgumentModelType.GetFlutterTypeName();
                             source.AppendLine($"\t\t\t{child.Name_Lower}: map['{child.Name_Upper}'] != null ? (map['{child.Name_Upper}'] as List).map((e)=>{model}.fromJson(e as Map<String,dynamic>)).toList() : null,");
                         }
                     }
                 }
+                else if (child is UserDefinedModeType || child is UserDefinedDerivedModelType)
+                {
+                    source.AppendLine($"\t\t\t{child.Name_Lower}: map['{child.Name_Upper}'] != null ? {child.GetFlutterTypeName()}.fromJson(map['{child.Name_Upper}']) : null,");
+                }
                 else
                 {
                     source.AppendLine($"\t\t\t{child.Name_Lower}: map['{child.Name_Upper}'],");