浏览代码

支持List枚举及简单类型的ToJson

felix 9 月之前
父节点
当前提交
35b482924f
共有 3 个文件被更改,包括 56 次插入0 次删除
  1. 28 0
      ModelTypes/ComplexModelType.cs
  2. 28 0
      ModelTypes/UserDefinedDerivedModelType.cs
  3. 二进制
      WingInterfaceLibrary.dll

+ 28 - 0
ModelTypes/ComplexModelType.cs

@@ -39,6 +39,34 @@ namespace FlutterCodeGenerator.ModelTypes
                     source.AppendLine($"\t\tif ({child.Name_Lower} != null)");
                     source.AppendLine($"\t\t\tmap['{child.Name_Upper}'] = JsonRpcUtils.dateFormat({child.Name_Lower}!);");
                 }
+                else if (child is ListModelType listModelType)
+                {
+                    if (listModelType.GenericArgumentModelType is EnumModelType)
+                    {
+                        source.AppendLine($"\t\tif ({child.Name_Lower} != null)");
+                        source.AppendLine($"\t\t\t{{");
+                        source.AppendLine($"\t\t\t\tList<String> {child.Name_Lower}List = {child.Name_Lower}!.map((e) {{");
+                        source.AppendLine($"\t\t\t\t\treturn e.index.toString();");
+                        source.AppendLine($"\t\t\t\t}}).toList();");
+                        source.AppendLine($"\t\t\t\tmap['{child.Name_Upper}'] = '[' + {child.Name_Lower}List.join(', ') + ']';");
+                        source.AppendLine($"\t\t\t}}");
+                    }
+                    else if (listModelType.GenericArgumentModelType is StringModelType)
+                    {
+                        source.AppendLine($"\t\tif ({child.Name_Lower} != null)");
+                        source.AppendLine($"\t\t\tmap['{child.Name_Upper}'] = '['+ {child.Name_Lower}!.join(',')+']';");
+                    }
+                    else if (listModelType.GenericArgumentModelType is SimpleModelType)
+                    {
+                        source.AppendLine($"\t\tif ({child.Name_Lower} != null)");
+                        source.AppendLine($"\t\t\tmap['{child.Name_Upper}'] = '['+ {child.Name_Lower}!.map((e) => e.toString()).join(',')+']';");
+                    }
+                    else
+                    {
+                        source.AppendLine($"\t\tif ({child.Name_Lower} != null)");
+                        source.AppendLine($"\t\t\tmap['{child.Name_Upper}'] = {child.Name_Lower};");
+                    }
+                }
                 else
                 {
                     source.AppendLine($"\t\tif ({child.Name_Lower} != null)");

+ 28 - 0
ModelTypes/UserDefinedDerivedModelType.cs

@@ -201,6 +201,34 @@ namespace FlutterCodeGenerator.ModelTypes
                             source.AppendLine($"\t\tif ({child.Name_Lower} != null)");
                             source.AppendLine($"\t\t\tmap['{child.Name_Upper}'] = JsonRpcUtils.dateFormat({child.Name_Lower}!);");
                         }
+                        else if (child is ListModelType listModelType)
+                        {
+                            if (listModelType.GenericArgumentModelType is EnumModelType)
+                            {
+                                source.AppendLine($"\t\tif ({child.Name_Lower} != null)");
+                                source.AppendLine($"\t\t\t{{");
+                                source.AppendLine($"\t\t\t\tList<String> {child.Name_Lower}List = {child.Name_Lower}!.map((e) {{");
+                                source.AppendLine($"\t\t\t\t\treturn e.index.toString();");
+                                source.AppendLine($"\t\t\t\t}}).toList();");
+                                source.AppendLine($"\t\t\t\tmap['{child.Name_Upper}'] = '[' + {child.Name_Lower}List.join(', ') + ']';");
+                                source.AppendLine($"\t\t\t}}");
+                            }
+                            else if (listModelType.GenericArgumentModelType is StringModelType)
+                            {
+                                source.AppendLine($"\t\tif ({child.Name_Lower} != null)");
+                                source.AppendLine($"\t\t\tmap['{child.Name_Upper}'] = '['+ {child.Name_Lower}!.join(',')+']';");
+                            }
+                            else if (listModelType.GenericArgumentModelType is SimpleModelType)
+                            {
+                                source.AppendLine($"\t\tif ({child.Name_Lower} != null)");
+                                source.AppendLine($"\t\t\tmap['{child.Name_Upper}'] = '['+ {child.Name_Lower}!.map((e) => e.toString()).join(',')+']';");
+                            }
+                            else
+                            {
+                                source.AppendLine($"\t\tif ({child.Name_Lower} != null)");
+                                source.AppendLine($"\t\t\tmap['{child.Name_Upper}'] = {child.Name_Lower};");
+                            }
+                        }
                         else
                         {
                             source.AppendLine($"\t\tif ({child.Name_Lower} != null)");

二进制
WingInterfaceLibrary.dll