Quellcode durchsuchen

修复当ModelType中无Children时,生成DartString格式异常的问题。

Felix vor 3 Jahren
Ursprung
Commit
c66ab50f2c
3 geänderte Dateien mit 70 neuen und 42 gelöschten Zeilen
  1. 4 4
      FlutterCodeGenerator.csproj
  2. 66 38
      ModeType.cs
  3. BIN
      WingInterfaceLibrary.dll

+ 4 - 4
FlutterCodeGenerator.csproj

@@ -5,6 +5,10 @@
     <TargetFramework>net6.0</TargetFramework>
   </PropertyGroup>
 
+  <ItemGroup>
+    <PackageReference Include="WingRpcSDK" Version="1.0.0.12" />
+  </ItemGroup>
+
 	<ItemGroup>
 		<None Update="WingInterfaceLibrary.dll">
 			<CopyToOutputDirectory>Always</CopyToOutputDirectory>
@@ -14,8 +18,4 @@
 		</None>
 	</ItemGroup>
 
-	<ItemGroup>
-	  <PackageReference Include="WingRpcSDK" Version="1.0.0.10" />
-	</ItemGroup>
-
 </Project>

+ 66 - 38
ModeType.cs

@@ -104,6 +104,7 @@ namespace FlutterCodeGenerator
         public VoidModelType(string name) : base(typeof(void), name)
         {
         }
+
         public override string GetFlutterTypeName(bool isDefault = true, bool isGenericName = false, bool isSingle = false)
         {
             return "void";
@@ -604,19 +605,26 @@ namespace FlutterCodeGenerator
                 }
             }
             dartString.AppendLine();
-            dartString.AppendLine($"\t{GetFlutterTypeName()}({{");
-            foreach (var child in Children)
+            if (Children.Count == 0)
             {
-                if (child.DefaultValue != null)
-                {
-                    dartString.AppendLine($"\t\tthis.{child.Name_Lower} = {child.DefaultValue},");
-                }
-                else
+                dartString.AppendLine($"\t{GetFlutterTypeName()}();");
+            }
+            else
+            {
+                dartString.AppendLine($"\t{GetFlutterTypeName()}({{");
+                foreach (var child in Children)
                 {
-                    dartString.AppendLine($"\t\tthis.{child.Name_Lower},");
+                    if (child.DefaultValue != null)
+                    {
+                        dartString.AppendLine($"\t\tthis.{child.Name_Lower} = {child.DefaultValue},");
+                    }
+                    else
+                    {
+                        dartString.AppendLine($"\t\tthis.{child.Name_Lower},");
+                    }
                 }
+                dartString.AppendLine("\t});");
             }
-            dartString.AppendLine("\t});");
             dartString.AppendLine();
 
             dartString.Append(FromJson(Children));
@@ -686,34 +694,65 @@ namespace FlutterCodeGenerator
                 }
             }
             dartString.AppendLine();
-            dartString.AppendLine($"\t{GetFlutterTypeName()}({{");
-            foreach (var child in Children)
+            if (Children.Count == 0)
             {
+                dartString.AppendLine($"\t{GetFlutterTypeName()}(");
                 if (baseType != null)
                 {
-                    if (baseType.Children.Any(x => x.ParameterType == child.ParameterType && x.Name_Upper == child.Name_Upper))
+                    dartString.AppendLine($"\t) : super(");
+                    foreach (var child in baseType.Children)
                     {
-                        var questionMark = QuestionMarkCheck(child);
-                        if (child.DefaultValue != null)
+                        dartString.AppendLine($"\t\t\t{child.Name_Lower}: {child.Name_Lower},");
+                    }
+                    dartString.AppendLine($"\t\t);");
+                }
+                else
+                {
+                    dartString.AppendLine("\t);");
+                }
+            }
+            else
+            {
+                dartString.AppendLine($"\t{GetFlutterTypeName()}({{");
+                foreach (var child in Children)
+                {
+                    if (baseType != null)
+                    {
+                        if (baseType.Children.Any(x => x.ParameterType == child.ParameterType && x.Name_Upper == child.Name_Upper))
                         {
-                            if (child is ListModelType || child is DictionaryModelType || child is UserDefinedGenericModelType)
+                            var questionMark = QuestionMarkCheck(child);
+                            if (child.DefaultValue != null)
                             {
-                                dartString.AppendLine($"\t\t{child.GetFlutterTypeName(false, false)}{questionMark} {child.Name_Lower} = {child.DefaultValue},");
+                                if (child is ListModelType || child is DictionaryModelType || child is UserDefinedGenericModelType)
+                                {
+                                    dartString.AppendLine($"\t\t{child.GetFlutterTypeName(false, false)}{questionMark} {child.Name_Lower} = {child.DefaultValue},");
+                                }
+                                else
+                                {
+                                    dartString.AppendLine($"\t\t{child.GetFlutterTypeName()}{questionMark} {child.Name_Lower} = {child.DefaultValue},");
+                                }
                             }
                             else
                             {
-                                dartString.AppendLine($"\t\t{child.GetFlutterTypeName()}{questionMark} {child.Name_Lower} = {child.DefaultValue},");
+                                if (child is ListModelType || child is DictionaryModelType || child is UserDefinedGenericModelType)
+                                {
+                                    dartString.AppendLine($"\t\t{child.GetFlutterTypeName(false, false)}{questionMark} {child.Name_Lower},");
+                                }
+                                else
+                                {
+                                    dartString.AppendLine($"\t\t{child.GetFlutterTypeName()}{questionMark} {child.Name_Lower},");
+                                }
                             }
                         }
                         else
                         {
-                            if (child is ListModelType || child is DictionaryModelType || child is UserDefinedGenericModelType)
+                            if (child.DefaultValue != null)
                             {
-                                dartString.AppendLine($"\t\t{child.GetFlutterTypeName(false, false)}{questionMark} {child.Name_Lower},");
+                                dartString.AppendLine($"\t\tthis.{child.Name_Lower} = {child.DefaultValue},");
                             }
                             else
                             {
-                                dartString.AppendLine($"\t\t{child.GetFlutterTypeName()}{questionMark} {child.Name_Lower},");
+                                dartString.AppendLine($"\t\tthis.{child.Name_Lower},");
                             }
                         }
                     }
@@ -729,30 +768,19 @@ namespace FlutterCodeGenerator
                         }
                     }
                 }
-                else
+                if (baseType != null)
                 {
-                    if (child.DefaultValue != null)
+                    dartString.AppendLine($"\t}}) : super(");
+                    foreach (var child in baseType.Children)
                     {
-                        dartString.AppendLine($"\t\tthis.{child.Name_Lower} = {child.DefaultValue},");
-                    }
-                    else
-                    {
-                        dartString.AppendLine($"\t\tthis.{child.Name_Lower},");
+                        dartString.AppendLine($"\t\t\t{child.Name_Lower}: {child.Name_Lower},");
                     }
+                    dartString.AppendLine($"\t\t);");
                 }
-            }
-            if (baseType != null)
-            {
-                dartString.AppendLine($"\t}}) : super(");
-                foreach (var child in baseType.Children)
+                else
                 {
-                    dartString.AppendLine($"\t\t\t{child.Name_Lower}: {child.Name_Lower},");
+                    dartString.AppendLine("\t});");
                 }
-                dartString.AppendLine($"\t\t);");
-            }
-            else
-            {
-                dartString.AppendLine("\t});");
             }
 
             dartString.AppendLine();

BIN
WingInterfaceLibrary.dll