소스 검색

追加Null Check

Felix 3 년 전
부모
커밋
8b7374a0c4
1개의 변경된 파일11개의 추가작업 그리고 11개의 파일을 삭제
  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,");
                         }
                     }
                 }