Browse Source

Minor command name list generator optimization

Krzysztof Krysiński 2 years ago
parent
commit
1da13a37fc

+ 1 - 3
src/PixiEditor/Models/Commands/CommandNameList.cs

@@ -1,6 +1,4 @@
-using System.Reflection;
-
-namespace PixiEditor.Models.Commands;
+namespace PixiEditor.Models.Commands;
 
 internal partial class CommandNameList
 {

+ 6 - 3
src/PixiEditorGen/CommandNameListGenerator.cs

@@ -105,7 +105,10 @@ internal partial class CommandNameList {
 
                 var parameters = string.Join(",", method.Item3.Select(x => $"typeof({x})"));
                 
-                code.AppendLine($"      Commands[typeof({method.Item1})].Add((\"{method.Item2}\", new Type[] {{ {parameters} }}));");
+                bool hasParameters = parameters.Length > 0;
+                string paramString = hasParameters ? $"new Type[] {{ {parameters} }}" : "Array.Empty<Type>()";
+                
+                code.AppendLine($"      Commands[typeof({method.Item1})].Add((\"{method.Item2}\", {paramString}));");
             }
 
             code.Append("   }\n}");
@@ -138,8 +141,8 @@ internal partial class CommandNameList {
                 else
                 {
                     var parameters = string.Join(",", method.Item3.Select(x => $"typeof({x})"));
-                
-                    code.AppendLine($"      Evaluators[typeof({method.Item1})].Add((\"{method.Item2}\", new Type[] {{ {parameters} }}));");
+                    string paramString = parameters.Length > 0 ? $"new Type[] {{ {parameters} }}" : "Array.Empty<Type>()";
+                    code.AppendLine($"      Evaluators[typeof({method.Item1})].Add((\"{method.Item2}\", {paramString}));");
                 }
             }