aboutsummaryrefslogtreecommitdiff
path: root/lib/VNLib.Plugins.Extensions.Loading/src/ConfigurationExtensions.cs
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2024-09-17 14:29:49 -0400
committerLibravatar vnugent <public@vaughnnugent.com>2024-09-17 14:29:49 -0400
commit711b12fa249cba9effecd4e722dd8d460d083659 (patch)
treed8007397d03eb519544652625fe516d0b0b904f8 /lib/VNLib.Plugins.Extensions.Loading/src/ConfigurationExtensions.cs
parentd2ced505e339d81a1d5954067f5766d42aa8d138 (diff)
feat: some mvc static routing extensionsdevelop
Diffstat (limited to 'lib/VNLib.Plugins.Extensions.Loading/src/ConfigurationExtensions.cs')
-rw-r--r--lib/VNLib.Plugins.Extensions.Loading/src/ConfigurationExtensions.cs107
1 files changed, 67 insertions, 40 deletions
diff --git a/lib/VNLib.Plugins.Extensions.Loading/src/ConfigurationExtensions.cs b/lib/VNLib.Plugins.Extensions.Loading/src/ConfigurationExtensions.cs
index 30711fa..149ab29 100644
--- a/lib/VNLib.Plugins.Extensions.Loading/src/ConfigurationExtensions.cs
+++ b/lib/VNLib.Plugins.Extensions.Loading/src/ConfigurationExtensions.cs
@@ -69,37 +69,6 @@ namespace VNLib.Plugins.Extensions.Loading
public const string PLUGIN_ASSET_KEY = "assets";
public const string PLUGINS_HOST_KEY = "plugins";
- /// <summary>
- /// Retrieves a top level configuration dictionary of elements for the specified type.
- /// The type must contain a <see cref="ConfigurationNameAttribute"/>
- /// </summary>
- /// <typeparam name="T">The type to get the configuration of</typeparam>
- /// <param name="plugin"></param>
- /// <returns>A <see cref="Dictionary{TKey, TValue}"/> of top level configuration elements for the type</returns>
- /// <exception cref="ConfigurationException"></exception>
- /// <exception cref="ObjectDisposedException"></exception>
- public static IConfigScope GetConfigForType<T>(this PluginBase plugin)
- {
- Type t = typeof(T);
- return plugin.GetConfigForType(t);
- }
-
- /// <summary>
- /// Retrieves a top level configuration dictionary of elements with the specified property name.
- /// </summary>
- /// <remarks>
- /// Search order: Plugin config, fall back to host config, throw if not found
- /// </remarks>
- /// <param name="plugin"></param>
- /// <param name="propName">The config property name to retrieve</param>
- /// <returns>A <see cref="IConfigScope"/> of top level configuration elements for the type</returns>
- /// <exception cref="ConfigurationException"></exception>
- /// <exception cref="ObjectDisposedException"></exception>
- public static IConfigScope GetConfig(this PluginBase plugin, string propName)
- {
- return TryGetConfig(plugin, propName)
- ?? throw new ConfigurationException($"Missing required top level configuration object '{propName}', in host/plugin configuration files");
- }
/// <summary>
/// Retrieves a top level configuration dictionary of elements with the specified property name,
@@ -116,7 +85,7 @@ namespace VNLib.Plugins.Extensions.Loading
{
plugin.ThrowIfUnloaded();
//Try to get the element from the plugin config first, or fallback to host
- if (plugin.PluginConfig.TryGetProperty(propName, out JsonElement el)
+ if (plugin.PluginConfig.TryGetProperty(propName, out JsonElement el)
|| plugin.HostConfig.TryGetProperty(propName, out el))
{
//Get the top level config as a dictionary
@@ -131,22 +100,80 @@ namespace VNLib.Plugins.Extensions.Loading
/// The type must contain a <see cref="ConfigurationNameAttribute"/>
/// </summary>
/// <param name="plugin"></param>
- /// <param name="type">The type to get configuration data for</param>
- /// <returns>A <see cref="IConfigScope"/> of top level configuration elements for the type</returns>
+ /// <param name="type">The class type to get the configuration scope variable from</param>
+ /// <returns>A <see cref="IConfigScope"/> for the desired top-level configuration scope</returns>
+ /// <exception cref="ConfigurationException"></exception>
/// <exception cref="ObjectDisposedException"></exception>
- public static IConfigScope GetConfigForType(this PluginBase plugin, Type type)
+ public static IConfigScope? TryGetConfigForType(this PluginBase plugin, Type type)
{
ArgumentNullException.ThrowIfNull(type);
string? configName = GetConfigNameForType(type);
- if (configName == null)
- {
- ThrowConfigNotFoundForType(type);
- }
+ return configName != null
+ ? TryGetConfig(plugin, configName)
+ : null;
+ }
- return plugin.GetConfig(configName);
+ /// <summary>
+ /// Retrieves a top level configuration dictionary of elements for the specified type.
+ /// The type must contain a <see cref="ConfigurationNameAttribute"/>
+ /// </summary>
+ /// <typeparam name="T">The type to get the configuration of</typeparam>
+ /// <param name="plugin"></param>
+ /// <returns>A <see cref="Dictionary{TKey, TValue}"/> of top level configuration elements for the type</returns>
+ /// <exception cref="ConfigurationException"></exception>
+ /// <exception cref="ObjectDisposedException"></exception>
+ public static IConfigScope? TryGetConfigForType<T>(this PluginBase plugin)
+ {
+ return TryGetConfigForType(plugin, typeof(T));
+ }
+
+ /// <summary>
+ /// Retrieves a top level configuration dictionary of elements for the specified type.
+ /// The type must contain a <see cref="ConfigurationNameAttribute"/>
+ /// </summary>
+ /// <param name="plugin"></param>
+ /// <param name="type">The type to get configuration data for</param>
+ /// <returns>A <see cref="IConfigScope"/> of top level configuration elements for the type</returns>
+ /// <exception cref="ObjectDisposedException"></exception>
+ public static IConfigScope GetConfigForType(this PluginBase plugin, Type type)
+ {
+ return TryGetConfigForType(plugin, type)
+ ?? throw new ConfigurationException($"Missing required configuration key for type {type.Name}");
+ }
+
+ /// <summary>
+ /// Retrieves a top level configuration dictionary of elements for the specified type.
+ /// The type must contain a <see cref="ConfigurationNameAttribute"/>
+ /// </summary>
+ /// <typeparam name="T">The type to get the configuration of</typeparam>
+ /// <param name="plugin"></param>
+ /// <returns>A <see cref="Dictionary{TKey, TValue}"/> of top level configuration elements for the type</returns>
+ /// <exception cref="ConfigurationException"></exception>
+ /// <exception cref="ObjectDisposedException"></exception>
+ public static IConfigScope GetConfigForType<T>(this PluginBase plugin)
+ {
+ return GetConfigForType(plugin, typeof(T));
+ }
+
+ /// <summary>
+ /// Retrieves a top level configuration dictionary of elements with the specified property name.
+ /// </summary>
+ /// <remarks>
+ /// Search order: Plugin config, fall back to host config, throw if not found
+ /// </remarks>
+ /// <param name="plugin"></param>
+ /// <param name="propName">The config property name to retrieve</param>
+ /// <returns>A <see cref="IConfigScope"/> of top level configuration elements for the type</returns>
+ /// <exception cref="ConfigurationException"></exception>
+ /// <exception cref="ObjectDisposedException"></exception>
+ public static IConfigScope GetConfig(this PluginBase plugin, string propName)
+ {
+ return TryGetConfig(plugin, propName)
+ ?? throw new ConfigurationException($"Missing required top level configuration object '{propName}', in host/plugin configuration files");
}
+
/// <summary>
/// Gets a required configuration property from the specified configuration scope