11using SquidStd . Core . Config . Internal ;
22using SquidStd . Core . Extensions . Directories ;
33using SquidStd . Core . Interfaces . Config ;
4+ using SquidStd . Core . Types . Yaml ;
45using SquidStd . Core . Yaml ;
56
67namespace SquidStd . Core . Config ;
@@ -25,6 +26,12 @@ public sealed class SquidStdConfig
2526 /// <summary>Gets the full path of the YAML configuration file.</summary>
2627 public string ConfigPath { get ; }
2728
29+ /// <summary>
30+ /// Gets the naming convention applied to YAML property keys when binding, composing and
31+ /// saving sections. Section names are always matched exactly as registered.
32+ /// </summary>
33+ public YamlNamingConventionType NamingConvention { get ; }
34+
2835 /// <summary>Gets the tracked sections (bound and unbound), ordered by priority then name.</summary>
2936 public IReadOnlyCollection < IConfigEntry > Entries
3037 {
@@ -37,12 +44,13 @@ public IReadOnlyCollection<IConfigEntry> Entries
3744 }
3845 }
3946
40- private SquidStdConfig ( string configName , string configDirectory , string rawYaml )
47+ private SquidStdConfig ( string configName , string configDirectory , string rawYaml , YamlNamingConventionType convention )
4148 {
4249 ConfigName = configName ;
4350 ConfigDirectory = configDirectory ;
4451 ConfigPath = ResolveConfigPath ( configName , configDirectory ) ;
4552 _rawYaml = rawYaml ;
53+ NamingConvention = convention ;
4654 }
4755
4856 /// <summary>
@@ -52,8 +60,13 @@ private SquidStdConfig(string configName, string configDirectory, string rawYaml
5260 /// </summary>
5361 /// <param name="configName">Logical configuration name or YAML file name.</param>
5462 /// <param name="configDirectory">Directory where the configuration file is searched.</param>
63+ /// <param name="convention">The naming convention applied to YAML property keys.</param>
5564 /// <returns>The loaded configuration.</returns>
56- public static SquidStdConfig Load ( string configName , string configDirectory )
65+ public static SquidStdConfig Load (
66+ string configName ,
67+ string configDirectory ,
68+ YamlNamingConventionType convention = YamlNamingConventionType . PascalCase
69+ )
5770 {
5871 ArgumentException . ThrowIfNullOrWhiteSpace ( configName ) ;
5972 ArgumentException . ThrowIfNullOrWhiteSpace ( configDirectory ) ;
@@ -62,7 +75,7 @@ public static SquidStdConfig Load(string configName, string configDirectory)
6275 var path = ResolveConfigPath ( configName , resolvedDirectory ) ;
6376 var raw = File . Exists ( path ) ? File . ReadAllText ( path ) : string . Empty ;
6477
65- return new ( configName , resolvedDirectory , raw ) ;
78+ return new ( configName , resolvedDirectory , raw , convention ) ;
6679 }
6780
6881 /// <summary>
@@ -134,7 +147,7 @@ public bool HasSection(string sectionName)
134147 lock ( _sync )
135148 {
136149 return ! string . IsNullOrWhiteSpace ( _rawYaml ) &&
137- YamlUtils . DeserializeSection ( _rawYaml , sectionName , typeof ( Dictionary < object , object > ) ) is not null ;
150+ YamlUtils . DeserializeSection ( _rawYaml , sectionName , typeof ( Dictionary < object , object > ) , NamingConvention ) is not null ;
138151 }
139152 }
140153
@@ -181,7 +194,7 @@ public string Compose()
181194 {
182195 lock ( _sync )
183196 {
184- return YamlUtils . SerializeSections ( BuildSectionMap ( ) ) ;
197+ return YamlUtils . SerializeSections ( BuildSectionMap ( ) , NamingConvention ) ;
185198 }
186199 }
187200
@@ -192,7 +205,7 @@ public void Save()
192205 {
193206 lock ( _sync )
194207 {
195- YamlUtils . SerializeToFile ( BuildSectionMap ( ) , ConfigPath ) ;
208+ YamlUtils . SerializeToFile ( BuildSectionMap ( ) , ConfigPath , NamingConvention ) ;
196209 }
197210 }
198211
@@ -223,7 +236,7 @@ private object Bind(ConfigSectionEntry entry)
223236 {
224237 var value = string . IsNullOrWhiteSpace ( _rawYaml )
225238 ? entry . CreateDefault ( )
226- : YamlUtils . DeserializeSection ( _rawYaml , entry . SectionName , entry . ConfigType ) ??
239+ : YamlUtils . DeserializeSection ( _rawYaml , entry . SectionName , entry . ConfigType , NamingConvention ) ??
227240 entry . CreateDefault ( ) ;
228241
229242 ConfigEnvSubstitution . Apply ( value ) ;
0 commit comments