-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConfigurationExtensions.cs
44 lines (35 loc) · 3.16 KB
/
ConfigurationExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* Configuration Visualizer
* Creates a visual of your program configuration (IConfiguration)
* (C) 2024 Charles Burns
* MIT license
* This code is meant as a small public service for use by the fine C# community.
*/
using FastCoreLib.LaunchPad.ExtensionMethodLogic;
using Microsoft.Extensions.Configuration;
namespace YourNamespace.ExtensionMethods;
/// <summary>Extension methods for <see cref="IConfiguration" /></summary>
public static class ConfigurationExtensions
{
/// <summary>Visualize the program configuration into a human-readable string</summary>
/// <remarks><see cref="Visualize(Microsoft.Extensions.Configuration.IConfiguration,System.Collections.Generic.IEnumerable{string})" /> will set the console output encoding to UTF-8. Use <see cref="VisualizeSimple(Microsoft.Extensions.Configuration.IConfiguration,bool)" /> to keep the output encoding unchanged.</remarks>
/// <param name="configuration">The program configuration</param>
/// <param name="excludePrefixes">Exclude configuration sections beginning with these prefixes. For example, to eliminate Microsoft internal configuration logic, use "Microsoft". These are case-insensitive</param>
/// <returns>A string with a beautiful visualization of your program configuration</returns>
public static string Visualize(this IConfiguration configuration, IEnumerable<string> excludePrefixes) =>
ConfigurationVisualizer.GenerateVisualization(configuration, true, new VisualizationSymbols.Unicode(), excludePrefixes);
/// <inheritdoc cref="Visualize(Microsoft.Extensions.Configuration.IConfiguration,System.Collections.Generic.IEnumerable{string})" />
/// <param name="excludeVendorSections">True to exclude common internal configuration sections which are often of little interest, or false to show the entire configuration object in all its verbose glory</param>
#pragma warning disable CS1573 // Parameter has no matching param tag in the XML comment (but other parameters do)
public static string Visualize(this IConfiguration configuration, bool excludeVendorSections = true) =>
#pragma warning restore CS1573 // Parameter has no matching param tag in the XML comment (but other parameters do)
ConfigurationVisualizer.GenerateVisualization(configuration, excludeVendorSections, new VisualizationSymbols.Unicode());
/// <inheritdoc cref="Visualize(Microsoft.Extensions.Configuration.IConfiguration,System.Boolean)" />
/// <returns>A string with a highly compatible ASCII visualization of your program configuration</returns>
public static string VisualizeSimple(this IConfiguration configuration, bool excludeVendorSections = true) =>
ConfigurationVisualizer.GenerateVisualization(configuration, excludeVendorSections, new VisualizationSymbols.Ascii());
/// <inheritdoc cref="Visualize(Microsoft.Extensions.Configuration.IConfiguration,System.Collections.Generic.IEnumerable{string})" />
/// <returns>A string with a highly compatible ASCII visualization of your program configuration</returns>
public static string VisualizeSimple(this IConfiguration configuration, IEnumerable<string> excludePrefixes) =>
ConfigurationVisualizer.GenerateVisualization(configuration, true, new VisualizationSymbols.Ascii(), excludePrefixes);
}