Răsfoiți Sursa

追加Null Check

Felix 3 ani în urmă
părinte
comite
8b7374a0c4
1 a modificat fișierele cu 11 adăugiri și 11 ștergeri
  1. 11 11
      ModeType.cs

+ 11 - 11
ModeType.cs

@@ -295,12 +295,12 @@ namespace FlutterCodeGenerator
                         else if (listModelType.GenericArgumentModelType is SimpleModelType)
                         {
                             var model = listModelType.GenericArgumentModelType.GetFlutterTypeName();
-                            source.AppendLine($"\t\t\t{child.Name_Lower}: map['{child.Name_Upper}'].cast<{model}>().toList(),");
+                            source.AppendLine($"\t\t\t{child.Name_Lower}: map['{child.Name_Upper}'] != null ? map['{child.Name_Upper}'].cast<{model}>().toList() : null,");
                         }
                         else
                         {
                             var model = listModelType.GenericArgumentModelType.GetFlutterTypeName();
-                            source.AppendLine($"\t\t\t{child.Name_Lower}: map['{child.Name_Upper}'].map((e)=>{model}.fromJson(e as Map<String,dynamic>)).toList(),");
+                            source.AppendLine($"\t\t\t{child.Name_Lower}: map['{child.Name_Upper}'] != null ? map['{child.Name_Upper}'].map((e)=>{model}.fromJson(e as Map<String,dynamic>)).toList() : null,");
                         }
                     }
                     else if (this is UserDefinedDerivedModelType definedDerivedModelType && definedDerivedModelType.BaseType is UserDefinedGenericModelType baseType)
@@ -312,12 +312,12 @@ namespace FlutterCodeGenerator
                         else if (listModelType.GenericArgumentModelType is SimpleModelType)
                         {
                             var model = listModelType.GenericArgumentModelType.GetFlutterTypeName();
-                            source.AppendLine($"\t\t\t{child.Name_Lower}: map['{child.Name_Upper}'].cast<{model}>().toList(),");
+                            source.AppendLine($"\t\t\t{child.Name_Lower}: map['{child.Name_Upper}'] != null ? map['{child.Name_Upper}'].cast<{model}>().toList() : null,");
                         }
                         else
                         {
                             var model = listModelType.GenericArgumentModelType.GetFlutterTypeName();
-                            source.AppendLine($"\t\t\t{child.Name_Lower}: map['{child.Name_Upper}'].map((e)=>{model}.fromJson(e as Map<String,dynamic>)).toList(),");
+                            source.AppendLine($"\t\t\t{child.Name_Lower}: map['{child.Name_Upper}'] != null ? map['{child.Name_Upper}'].map((e)=>{model}.fromJson(e as Map<String,dynamic>)).toList() : null,");
                         }
                     }
                     else if (this is UserDefinedModeType || this is UserDefinedDerivedModelType)
@@ -325,12 +325,12 @@ namespace FlutterCodeGenerator
                         if (listModelType.GenericArgumentModelType is SimpleModelType)
                         {
                             var model = listModelType.GenericArgumentModelType.GetFlutterTypeName();
-                            source.AppendLine($"\t\t\t{child.Name_Lower}: map['{child.Name_Upper}'].cast<{model}>().toList(),");
+                            source.AppendLine($"\t\t\t{child.Name_Lower}: map['{child.Name_Upper}'] != null ? map['{child.Name_Upper}'].cast<{model}>().toList() : null,");
                         }
                         else
                         {
                             var model = listModelType.GenericArgumentModelType.GetFlutterTypeName();
-                            source.AppendLine($"\t\t\t{child.Name_Lower}: map['{child.Name_Upper}'].map((e)=>{model}.fromJson(e as Map<String,dynamic>)).toList(),");
+                            source.AppendLine($"\t\t\t{child.Name_Lower}: map['{child.Name_Upper}'] != null ? map['{child.Name_Upper}'].map((e)=>{model}.fromJson(e as Map<String,dynamic>)).toList() : null,");
                         }
                     }
                 }
@@ -338,7 +338,7 @@ namespace FlutterCodeGenerator
                 {
                     var argumentName1 = dictionaryModelType.GenericArgumentModelTypeList[0].GetFlutterTypeName();
                     var argumentName2 = dictionaryModelType.GenericArgumentModelTypeList[1].GetFlutterTypeName();
-                    source.AppendLine($"\t\t\t{child.Name_Lower}: map['{child.Name_Upper}'].cast<{argumentName1},{argumentName2}>(),");
+                    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)
                 {
@@ -351,12 +351,12 @@ namespace FlutterCodeGenerator
                         else if (userDefinedGenericComplexModelType.GenericArgumentModelType is SimpleModelType)
                         {
                             var model = userDefinedGenericComplexModelType.GenericArgumentModelType.GetFlutterTypeName();
-                            source.AppendLine($"\t\t\t{child.Name_Lower}: map['{child.Name_Upper}'].cast<{model}>().toList(),");
+                            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();
-                            source.AppendLine($"\t\t\t{child.Name_Lower}: map['{child.Name_Upper}'].map((e)=>{model}.fromJson(e as Map<String,dynamic>)).toList(),");
+                            source.AppendLine($"\t\t\t{child.Name_Lower}: map['{child.Name_Upper}'] != null ? map['{child.Name_Upper}'].map((e)=>{model}.fromJson(e as Map<String,dynamic>)).toList() : null,");
                         }
                     }
                     else if (this is UserDefinedModeType)
@@ -364,12 +364,12 @@ namespace FlutterCodeGenerator
                         if (userDefinedGenericComplexModelType.GenericArgumentModelType is SimpleModelType)
                         {
                             var model = userDefinedGenericComplexModelType.GenericArgumentModelType.GetFlutterTypeName();
-                            source.AppendLine($"\t\t\t{child.Name_Lower}: map['{child.Name_Upper}'].cast<{model}>().toList(),");
+                            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();
-                            source.AppendLine($"\t\t\t{child.Name_Lower}: map['{child.Name_Upper}'].map((e)=>{model}.fromJson(e as Map<String,dynamic>)).toList(),");
+                            source.AppendLine($"\t\t\t{child.Name_Lower}: map['{child.Name_Upper}'] != null ? map['{child.Name_Upper}'].map((e)=>{model}.fromJson(e as Map<String,dynamic>)).toList() : null,");
                         }
                     }
                 }