Pārlūkot izejas kodu

修复Bug:多次生成PageCollection.
数组的转换。

Felix 3 gadi atpakaļ
vecāks
revīzija
2cc5ed5c5a
4 mainītis faili ar 38 papildinājumiem un 12 dzēšanām
  1. 1 1
      .vscode/launch.json
  2. 20 9
      ModeType.cs
  3. 17 2
      ServiceMap.cs
  4. BIN
      WingInterfaceLibrary.dll

+ 1 - 1
.vscode/launch.json

@@ -10,7 +10,7 @@
             "request": "launch",
             "preLaunchTask": "build",
             // If you have changed target frameworks, make sure to update the program path.
-            "program": "${workspaceFolder}/bin/Debug/net5.0/FlutterCodeGenerator.dll",
+            "program": "${workspaceFolder}/bin/Debug/net6.0/FlutterCodeGenerator.dll",
             "args": [],
             "cwd": "${workspaceFolder}",
             // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console

+ 20 - 9
ModeType.cs

@@ -150,7 +150,7 @@ namespace FlutterCodeGenerator
         {
             var source = new StringBuilder();
             string flutterTypeName = null;
-            if(this is UserDefinedGenericComplexModelType)
+            if (this is UserDefinedGenericComplexModelType)
             {
                 flutterTypeName = GetFlutterTypeName(false, false, true);
             }
@@ -204,9 +204,20 @@ namespace FlutterCodeGenerator
                 }
                 else if (child is ArrayModelType)
                 {
-                    source.AppendLine($"\t\t\t{child.Name_Lower}: {child.Name_Lower}Data != null ? ({child.Name_Lower}Data as List).map((e) => {child.ParameterType.Name.Replace("[]", string.Empty)}.fromJson(e)).toList(): const [],");
+
+                    var arrayTypeName = child.ParameterType.FullName.Replace("[]", string.Empty);
+                    var arrayType = child.ParameterType.Assembly.GetType(arrayTypeName);
+                    var modelType = ModelTypeGenerator.Create(arrayType, "");
+                    if (modelType is SimpleModelType)
+                    {
+                        source.AppendLine($"\t\t\t{child.Name_Lower}: {child.Name_Lower}Data != null ? ({child.Name_Lower}Data as List).map((e) => e as {child.ParameterType.Name.Replace("[]", string.Empty)}).toList(): const [],");
+                    }
+                    else
+                    {
+                        source.AppendLine($"\t\t\t{child.Name_Lower}: {child.Name_Lower}Data != null ? ({child.Name_Lower}Data as List).map((e) => {child.ParameterType.Name.Replace("[]", string.Empty)}.fromJson(e)).toList(): const [],");
+                    }
                 }
-                else if(child is DateTimeModeType)
+                else if (child is DateTimeModeType)
                 {
                     source.AppendLine($"\t\t\t{child.Name_Lower}: map['{child.Name_Upper}'] != null ? DateTime.parse(map['{child.Name_Upper}']) : null,");
                 }
@@ -319,9 +330,9 @@ namespace FlutterCodeGenerator
     {
         public ArrayModelType(Type type, string name) : base(type, name)
         {
-            var arraytypeName = ParameterType.FullName.Replace("[]", string.Empty);
-            var arraytype = ParameterType.Assembly.GetType(arraytypeName);
-            ModelTypeGenerator.Create(arraytype, "");
+            var arrayTypeName = ParameterType.FullName.Replace("[]", string.Empty);
+            var arrayType = ParameterType.Assembly.GetType(arrayTypeName);
+            ModelTypeGenerator.Create(arrayType, "");
         }
 
         public override string GetFlutterTypeName(bool isDefault = true, bool isGenericName = false, bool isSingle = false)
@@ -361,7 +372,7 @@ namespace FlutterCodeGenerator
     }
 
     /// <summary>
-    /// Dictionary Type�� Ĭ��û�и�����
+    /// Dictionary Type
     /// </summary>
     public class DictionaryModelType : SimpleModelType
     {
@@ -395,7 +406,7 @@ namespace FlutterCodeGenerator
     }
 
     /// <summary>
-    /// �Զ��巺�͸����࣬Ĭ��һά
+    /// User Defined Generic Complex Model Type
     /// </summary>
     public class UserDefinedGenericComplexModelType : ComplexModelType
     {
@@ -456,7 +467,7 @@ namespace FlutterCodeGenerator
                 dartString.AppendLine($"\t{argumentName}{questionMark} {child.Name_Lower};");
             }
             dartString.AppendLine();
-            dartString.AppendLine($"\t{GetFlutterTypeName(false,false,true)}({{");
+            dartString.AppendLine($"\t{GetFlutterTypeName(false, false, true)}({{");
             foreach (var child in Children)
             {
                 if (child.DefaultValue != null)

+ 17 - 2
ServiceMap.cs

@@ -11,6 +11,7 @@ namespace FlutterCodeGenerator
 
         public static List<ComplexModelType> TemporaryList { get; set; }
         private List<ComplexModelType> _usedComplexModelTypeList;
+        private List<Type> _userDefinedGenericTypeList;
         private List<string> _userDefinedComplexReturnTypeList;
         private string _serviceName;
 
@@ -21,13 +22,14 @@ namespace FlutterCodeGenerator
             MethodMapList = new List<MethodMap>();
             var methodsList = type.GetMethods();
             _serviceName = type.Name[1..];
-
+            _userDefinedGenericTypeList = new List<Type>();
             foreach (var method in methodsList)
             {
                 var methodMap = new MethodMap(method);
                 MethodMapList.Add(methodMap);
             }
             _usedComplexModelTypeList.AddRange(TemporaryList);
+            TemporaryList.Clear();
         }
 
         public string GetServiceModelDartString()
@@ -35,7 +37,20 @@ namespace FlutterCodeGenerator
             var dartString = new StringBuilder();
             foreach (var modelType in _usedComplexModelTypeList)
             {
-                dartString.AppendLine(modelType.GetDartString());
+                if (modelType is UserDefinedGenericComplexModelType)
+                {
+                    var genericType = modelType.ParameterType.GetGenericTypeDefinition();
+                    if (!_userDefinedGenericTypeList.Contains(genericType))
+                    {
+                        dartString.AppendLine(modelType.GetDartString());
+                        _userDefinedGenericTypeList.Add(genericType);
+                    }
+                }
+                else
+                {
+                    dartString.AppendLine(modelType.GetDartString());
+                }
+
             }
             if (string.IsNullOrWhiteSpace(dartString.ToString()))
             {

BIN
WingInterfaceLibrary.dll