33
44namespace Sharpy
55{
6+ /// <summary>Parses and stores INI-style configuration data.</summary>
67 [ SharpyModuleType ( "configparser" ) ]
78 public sealed partial class ConfigParser
89 {
@@ -17,12 +18,14 @@ public sealed partial class ConfigParser
1718 private readonly IInterpolation _interpolation ;
1819 private readonly bool _allowNoValue ;
1920
21+ /// <summary>Initializes a new config parser.</summary>
2022 public ConfigParser ( IInterpolation ? interpolation = null , bool allowNoValue = false )
2123 {
2224 _interpolation = interpolation ?? new BasicInterpolation ( ) ;
2325 _allowNoValue = allowNoValue ;
2426 }
2527
28+ /// <summary>Gets a proxy for the named section.</summary>
2629 public SectionProxy this [ string section ]
2730 {
2831 get
@@ -36,11 +39,13 @@ public SectionProxy this[string section]
3639 }
3740 }
3841
42+ /// <summary>Returns the non-default section names.</summary>
3943 public SCG . List < string > Sections ( )
4044 {
4145 return new SCG . List < string > ( _sections . Keys ) ;
4246 }
4347
48+ /// <summary>Adds a new section.</summary>
4449 public void AddSection ( string section )
4550 {
4651 if ( string . Equals ( section , DefaultSectionName , StringComparison . OrdinalIgnoreCase ) )
@@ -54,6 +59,7 @@ public void AddSection(string section)
5459 _sections [ section ] = new SCG . Dictionary < string , string ? > ( StringComparer . OrdinalIgnoreCase ) ;
5560 }
5661
62+ /// <summary>Determines whether a non-default section exists.</summary>
5763 public bool HasSection ( string section )
5864 {
5965 if ( string . Equals ( section , DefaultSectionName , StringComparison . OrdinalIgnoreCase ) )
@@ -63,6 +69,7 @@ public bool HasSection(string section)
6369 return _sections . ContainsKey ( section ) ;
6470 }
6571
72+ /// <summary>Removes a non-default section.</summary>
6673 public bool RemoveSection ( string section )
6774 {
6875 if ( string . Equals ( section , DefaultSectionName , StringComparison . OrdinalIgnoreCase ) )
@@ -72,6 +79,7 @@ public bool RemoveSection(string section)
7279 return _sections . Remove ( section ) ;
7380 }
7481
82+ /// <summary>Gets an option value, optionally applying interpolation.</summary>
7583 public string ? Get ( string section , string option , string ? fallback = null , bool raw = false )
7684 {
7785 string normalizedOption = option . ToLowerInvariant ( ) ;
@@ -112,6 +120,7 @@ public bool RemoveSection(string section)
112120 return _interpolation . BeforeGet ( this , section , normalizedOption , rawValue ) ;
113121 }
114122
123+ /// <summary>Gets an option as an integer.</summary>
115124 public int GetInt ( string section , string option , int ? fallback = null )
116125 {
117126 string ? value = null ;
@@ -131,6 +140,7 @@ public int GetInt(string section, string option, int? fallback = null)
131140 return result ;
132141 }
133142
143+ /// <summary>Gets an option as a floating-point number.</summary>
134144 public double GetFloat ( string section , string option , double ? fallback = null )
135145 {
136146 string ? value = null ;
@@ -151,6 +161,7 @@ public double GetFloat(string section, string option, double? fallback = null)
151161 return result ;
152162 }
153163
164+ /// <summary>Gets an option as a boolean using configparser truth values.</summary>
154165 public bool GetBoolean ( string section , string option , bool ? fallback = null )
155166 {
156167 string ? value = null ;
@@ -185,6 +196,7 @@ public bool GetBoolean(string section, string option, bool? fallback = null)
185196 }
186197 }
187198
199+ /// <summary>Sets an option value in a section.</summary>
188200 public void Set ( string section , string option , string value )
189201 {
190202 string normalizedOption = option . ToLowerInvariant ( ) ;
@@ -201,6 +213,7 @@ public void Set(string section, string option, string value)
201213 _sections [ section ] [ normalizedOption ] = value ;
202214 }
203215
216+ /// <summary>Determines whether a section or defaults contain an option.</summary>
204217 public bool HasOption ( string section , string option )
205218 {
206219 string normalizedOption = option . ToLowerInvariant ( ) ;
@@ -216,6 +229,7 @@ public bool HasOption(string section, string option)
216229 return _sections [ section ] . ContainsKey ( normalizedOption ) || _defaults . ContainsKey ( normalizedOption ) ;
217230 }
218231
232+ /// <summary>Removes an option from a section or from defaults.</summary>
219233 public bool RemoveOption ( string section , string option )
220234 {
221235 string normalizedOption = option . ToLowerInvariant ( ) ;
@@ -231,6 +245,7 @@ public bool RemoveOption(string section, string option)
231245 return _sections [ section ] . Remove ( normalizedOption ) ;
232246 }
233247
248+ /// <summary>Returns the option names available in a section.</summary>
234249 public SCG . List < string > Options ( string section )
235250 {
236251 if ( string . Equals ( section , DefaultSectionName , StringComparison . OrdinalIgnoreCase ) )
@@ -254,6 +269,7 @@ public SCG.List<string> Options(string section)
254269 return new SCG . List < string > ( result ) ;
255270 }
256271
272+ /// <summary>Returns the section items with defaults applied.</summary>
257273 public SCG . Dictionary < string , string > Items ( string section )
258274 {
259275 if ( ! string . Equals ( section , DefaultSectionName , StringComparison . OrdinalIgnoreCase )
@@ -287,6 +303,7 @@ public SCG.Dictionary<string, string> Items(string section)
287303 return result ;
288304 }
289305
306+ /// <summary>Returns the default section values.</summary>
290307 public SCG . Dictionary < string , string > Defaults ( )
291308 {
292309 var result = new SCG . Dictionary < string , string > ( StringComparer . OrdinalIgnoreCase ) ;
0 commit comments