Feature Request: ObjectToIni() output set types as CSV format
Regarding commit 6d77e94b, IniToObject() now supports reading set types in CSV format (e.g., Methods=get,head), which is very convenient and more readable than JSON arrays.
However, I noticed that ObjectToIni() still outputs set types in JSON array format: LogLevels=["Info","Warning","Error","Custom1"]
Instead of the cleaner CSV format: LogLevels=Info,Warning,Error,Custom1
Would it be possible to have ObjectToIni() output set types in CSV format as well? This would make TSynJsonFileSettings.SaveIfNeeded produce INI files with consistent read/write format, and the resulting files would be more human-friendly to edit.
Please try with today's commit.
ObjectToIni() should be paired with IniToObject() unserialization level now. As paired with those tests.
Thank you for the quick implementation! I've pulled the latest commits and verified the changes. Everything works perfectly now.
Test Results:
- ObjectToIni now outputs CSV format for sets: LogLevels=Info,Warning,Error,Exception,Custom1
- Instead of the previous JSON array format ["Info","Warning",...]
- Round-trip test passed: - Original: LogLevels=[Info,Warning,Error,Exception,Custom1] - Saved via ObjectToIni: LogLevels=Info,Warning,Error,Exception,Custom1 - Loaded via IniToObject: LogLevels=[Info,Warning,Error,Exception,Custom1] - ✅ Round-trip OK: TRUE
- Both read formats still work: - CSV format: LogLevels=Info,Warning,Error ✅ - JSON format: LogLevels=["Info","Warning","Error"] ✅
The new TIniFeatures parameter and the refactored ObjectToIni implementation provide a clean, consistent read/write experience. The optional woHumanReadableEnumSetAsComment producing a values comment is a nice touch for human-editable config files.
Great work! 👍
I noticed that when using TSynJsonFileSettings with fsoWriteIni, the output now includes helpful comments showing all possible enum/set values:
[Main] ; values=None,Info,Debug,Trace,Warning,Error,... LogLevels=Info,Warning,Error,Custom1
While this is useful for documentation purposes, in some production scenarios we prefer cleaner config files without these comments.
Suggestion: Add a new option like fsoNoEnumSetComment in TFileSettingsOptions to allow disabling the woHumanReadableEnumSetAsComment behavior when saving INI files.
Currently, the workaround is to override SaveIfNeeded, but a built-in option would be cleaner:
TFileSettingsOptions = set of ( fsoDisableSaveIfNeeded, fsoReadIni, fsoWriteIni, fsoNoEnumSetComment // New option to disable enum/set comments );
Then in SaveIfNeeded: if fsoWriteIni in fSettingsOptions then if fsoNoEnumSetComment in fSettingsOptions then saved := ObjectToIni(self, fSectionName, [woEnumSetsAsText, woRawBlobAsBase64]) else saved := ObjectToIni(self, fSectionName);
Thank you for considering this enhancement!
Good idea.
See above.
Confirm! It works perfectly.