Created
January 31, 2023 01:19
-
-
Save Swimburger/c65a48a3b6034f063876608b48bf9847 to your computer and use it in GitHub Desktop.
Replace empty strings with `null` recursively in .NET configuration sections
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void ChangeEmptyStringToNull(IConfigurationSection configSection) | |
{ | |
if (configSection == null) return; | |
if (configSection.Value == "") configSection.Value = null; | |
foreach (var childConfigSection in configSection.GetChildren()) | |
{ | |
ChangeEmptyStringToNull(childConfigSection); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment