Created
April 3, 2018 07:26
-
-
Save configureappio/826c6cb896f93b3cd2c1cee11d83aa35 to your computer and use it in GitHub Desktop.
Example of configuration settings validator
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
public class SettingsValidator : ISettingsValidator | |
{ | |
public bool TryValidate(IAppSettingsStructure settings, out AggregateException validationExceptions) | |
{ | |
if (settings == null) throw new ArgumentNullException(nameof(settings)); | |
var exceptions = new List<Exception>(); | |
if (settings.ApplicationName == null) exceptions.Add(new ArgumentNullException(nameof(settings.ApplicationName))); | |
if (string.IsNullOrWhiteSpace(settings.ApplicationName)) exceptions.Add(new ArgumentOutOfRangeException(nameof(settings.ApplicationName))); | |
if (settings.Secrets == null) exceptions.Add(new ArgumentNullException(nameof(settings.ApplicationName))); | |
validationExceptions = new AggregateException(exceptions); | |
return !exceptions.Any(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment