public OptionsDumper(IEnumerable <Type> optionSections) { _optionSections = optionSections; _sortOrder = _optionSections.SelectMany(optionSection => optionSection.GetProperties() .Select(p => NameTranslators.CombineByPascalCase(p.Name, " ").ToUpper())) .ToList(); }
public static string DumpOptions() { if (_effectiveOptions == null) { return("No options have been parsed"); } var dumpOptionsBuilder = new StringBuilder(); var defaultOptionsHeading = "DEFAULT OPTIONS:"; var displayingModifiedOptions = true; dumpOptionsBuilder.AppendLine("MODIFIED OPTIONS:"); dumpOptionsBuilder.AppendLine(); if (_effectiveOptions.Count(x => !x.Source.ToLower().Contains("default")) == 0) { dumpOptionsBuilder.AppendLine("NONE"); dumpOptionsBuilder.AppendLine(); dumpOptionsBuilder.AppendLine(defaultOptionsHeading); dumpOptionsBuilder.AppendLine(); displayingModifiedOptions = false; } foreach (var option in _effectiveOptions.OrderBy(x => x.Source.ToLower().Contains("default") ? 1 : 0)) { if (option.Source.ToLower().Contains("default") && displayingModifiedOptions) { dumpOptionsBuilder.AppendLine(); dumpOptionsBuilder.AppendLine(defaultOptionsHeading); dumpOptionsBuilder.AppendLine(); displayingModifiedOptions = false; } var value = option.Value; if (option.Mask && displayingModifiedOptions) { value = "****"; } var optionName = NameTranslators.CombineByPascalCase(option.Name, " ").ToUpper(); var valueToDump = value == null ? String.Empty : value.ToString(); if (value is Array) { valueToDump = String.Empty; var collection = value as Array; if (collection.Length > 0) { valueToDump = "[ " + String.Join(", ", (IEnumerable <object>)value) + " ]"; } } dumpOptionsBuilder.AppendLine(String.Format("\t{0,-25} {1} ({2})", optionName + ":", String.IsNullOrEmpty(valueToDump) ? "<empty>" : valueToDump, option.Source)); } return(dumpOptionsBuilder.ToString()); }
static string FormatSourceName(Type source) => $"({(source == typeof(Default) ? "<DEFAULT>" : NameTranslators.CombineByPascalCase(source.Name, " "))})" ;