aboutsummaryrefslogtreecommitdiff
path: root/lib/VNLib.Plugins.Extensions.Loading/src/ConfigurationExtensions.cs
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2023-11-02 01:50:05 -0400
committerLibravatar vnugent <public@vaughnnugent.com>2023-11-02 01:50:05 -0400
commit9768aa7713826d49a6c2ea1025caa4b87d62e5e8 (patch)
tree327525a94b1fbe8b11591eeb1b3d2941a6e58c06 /lib/VNLib.Plugins.Extensions.Loading/src/ConfigurationExtensions.cs
parentc5b9f9b64933a288362fc08bea8a461e5e260b16 (diff)
also carried away
Diffstat (limited to 'lib/VNLib.Plugins.Extensions.Loading/src/ConfigurationExtensions.cs')
-rw-r--r--lib/VNLib.Plugins.Extensions.Loading/src/ConfigurationExtensions.cs19
1 files changed, 14 insertions, 5 deletions
diff --git a/lib/VNLib.Plugins.Extensions.Loading/src/ConfigurationExtensions.cs b/lib/VNLib.Plugins.Extensions.Loading/src/ConfigurationExtensions.cs
index ccb2341..06c3ee4 100644
--- a/lib/VNLib.Plugins.Extensions.Loading/src/ConfigurationExtensions.cs
+++ b/lib/VNLib.Plugins.Extensions.Loading/src/ConfigurationExtensions.cs
@@ -205,11 +205,11 @@ namespace VNLib.Plugins.Extensions.Loading
//Get the property
if(!config.TryGetValue(property, out JsonElement el))
{
- throw new KeyNotFoundException($"Missing required configuration property '{property}'");
+ throw new KeyNotFoundException($"Missing required configuration property '{property}' in config {config.ScopeName}");
}
//Even if the getter returns null, throw
- return getter(el) ?? throw new KeyNotFoundException($"Missing required configuration property '{property}'");
+ return getter(el) ?? throw new KeyNotFoundException($"Missing required configuration property '{property}' in config {config.ScopeName}");
}
/// <summary>
@@ -301,12 +301,21 @@ namespace VNLib.Plugins.Extensions.Loading
/// <typeparam name="T"></typeparam>
/// <param name="plugin"></param>
/// <returns>True if the plugin config contains the require configuration property</returns>
- public static bool HasConfigForType<T>(this PluginBase plugin)
+ public static bool HasConfigForType<T>(this PluginBase plugin) => HasConfigForType(plugin, typeof(T));
+
+
+ /// <summary>
+ /// Determines if the current plugin configuration contains the require properties to initialize
+ /// the type
+ /// </summary>
+ /// <param name="type">The type to get the configuration for</param>
+ /// <param name="plugin"></param>
+ /// <returns>True if the plugin config contains the require configuration property</returns>
+ public static bool HasConfigForType(this PluginBase plugin, Type type)
{
- Type type = typeof(T);
ConfigurationNameAttribute? configName = type.GetCustomAttribute<ConfigurationNameAttribute>();
//See if the plugin contains a configuration varables
- return configName != null && (
+ return configName != null && (
plugin.PluginConfig.TryGetProperty(configName.ConfigVarName, out _) ||
plugin.HostConfig.TryGetProperty(configName.ConfigVarName, out _)
);