@@ -80,12 +80,12 @@ public async Task WritePartAsync(Part part)
8080 SetSymbolId ( symbol , part . Value ) ;
8181 UpdateUnitIds ( symbol , symbolInfo . Name , part . Value ) ;
8282
83- SetPropertyByName ( symbol , "Reference" , part . Reference ) ;
84- SetPropertyByName ( symbol , "Value" , part . Value ) ;
85- SetPropertyByName ( symbol , "Footprint" , part . Footprint ) ;
86- SetPropertyByName ( symbol , "Datasheet" , string . IsNullOrEmpty ( part . Datasheet ) ? "~" : part . Datasheet ) ;
87- SetPropertyByName ( symbol , "ki_keywords" , part . Keywords ) ;
88- SetPropertyByName ( symbol , "ki_description" , part . Description ) ;
83+ SetOrAddPropertyByName ( symbol , "Reference" , part . Reference ) ;
84+ SetOrAddPropertyByName ( symbol , "Value" , part . Value ) ;
85+ SetOrAddPropertyByName ( symbol , "Footprint" , part . Footprint ) ;
86+ SetOrAddPropertyByName ( symbol , "Datasheet" , string . IsNullOrEmpty ( part . Datasheet ) ? "~" : part . Datasheet ) ;
87+ SetOrAddPropertyByName ( symbol , "ki_keywords" , part . Keywords ) ;
88+ SetOrAddPropertyByName ( symbol , "ki_description" , part . Description ) ;
8989
9090 foreach ( var customField in part . CustomFields . OrderBy ( cf => cf . Key ) )
9191 {
@@ -113,20 +113,23 @@ private static void UpdateUnitIds(SNode symbol, string symbolName, string partVa
113113 }
114114 }
115115
116- private static void SetPropertyByName ( SNode symbol , string propertyName , string value )
116+ private static void SetOrAddPropertyByName ( SNode symbol , string propertyName , string value )
117117 {
118118 var property = symbol . Childs
119119 . Where ( child => child . Name == _property )
120120 . SingleOrDefault ( property => property . Childs [ 0 ] . Name == propertyName ) ;
121121
122- if ( property is null )
122+ if ( property is not null )
123123 {
124- var symbolName = symbol . Childs [ 0 ] . Name ;
125- throw new KeyNotFoundException ( $ "Property \" { propertyName } \" not found in symbol\" { symbolName } \" .") ;
124+ property . Childs [ 1 ] . Name = value ;
125+ property . Childs [ 1 ] . IsString = true ;
126+ }
127+ else
128+ {
129+ var index = GetIndexOfLastProperty ( symbol ) + 1 ;
130+ property = CreateCustomProperty ( null , KeyValuePair . Create ( propertyName , value ) ) ;
131+ symbol . Insert ( index , property ) ;
126132 }
127-
128- property . Childs [ 1 ] . Name = value ;
129- property . Childs [ 1 ] . IsString = true ;
130133 }
131134
132135 private static void AddCustomProperty ( SNode symbol , KeyValuePair < string , string > property )
@@ -176,7 +179,7 @@ private static SNode CreateCustomProperty(int? propertyId, KeyValuePair<string,
176179 }
177180
178181 return symbol . Childs
179- . Where ( child => child . Name == "property" )
182+ . Where ( child => child . Name == _property )
180183 . Select ( GetIdOfProperty )
181184 . Last ( ) ;
182185 }
0 commit comments