Skip to content

Instantly share code, notes, and snippets.

@configureappio
Created April 3, 2018 07:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save configureappio/826c6cb896f93b3cd2c1cee11d83aa35 to your computer and use it in GitHub Desktop.
Save configureappio/826c6cb896f93b3cd2c1cee11d83aa35 to your computer and use it in GitHub Desktop.
Example of configuration settings validator
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