瀏覽代碼

Properties must be unique

Piotr Czajkowski 4 月之前
父節點
當前提交
15bb319e2e

+ 2 - 2
CodeGenerators/CodeGenerators/ClassRecordGenerator.cs

@@ -5,7 +5,7 @@ namespace CodeGenerators;
 public class ClassRecordGenerator : IGenerator
 {
     public List<string> Usings { get; set; } = new List<string>();
-    public List<Property> Properties { get; set; } = new List<Property>();
+    public Dictionary<string, Property> Properties { get; set; } = new Dictionary<string, Property>();
     private readonly string namespaceName;
     private readonly string name;
     private readonly bool isRecord;
@@ -35,7 +35,7 @@ public class ClassRecordGenerator : IGenerator
         indent++;
 
         if (Properties.Any())
-            sb.AppendLine(string.Join("\n\n", Properties.Select(x => x.Build(indent))));
+            sb.AppendLine(string.Join("\n\n", Properties.Select(x => x.Value.Build(indent))));
 
         indent--;
         sb.AppendLine("}");

+ 1 - 0
CodeGenerators/CodeGenerators/Property.cs

@@ -5,6 +5,7 @@ namespace CodeGenerators;
 public class Property : IGenerator
 {
     private readonly string name;
+    public string Name => name;
     private readonly string type;
     public List<AttributeElement> Attributes { get; set; } = new List<AttributeElement>();
 

+ 2 - 2
CodeGenerators/CodeGeneratorsTests/ClassRecordGeneratorTests.cs

@@ -13,11 +13,11 @@ public class ClassRecordGeneratorTests
         
         var property = new Property("TestProperty", "string");
         property.Attributes.Add(new AttributeElement("Column", "Test Property"));
-        test.Properties.Add(property);
+        test.Properties.Add(property.Name, property);
 
         var secondProperty = new Property("SecondProperty", "int");
         secondProperty.Attributes.Add(new AttributeElement("Column", "Second Property"));
-        test.Properties.Add(secondProperty);
+        test.Properties.Add(secondProperty.Name, secondProperty);
 
         var result = test.Build();
         Assert.NotEmpty(result);