Provides static validation utilities for query analysis extension configurations. The class exposes a set of methods and a property that allow callers to check the correctness of extension parameters, retrieve detailed error messages, and enforce validity at runtime.
public static IReadOnlyList<string> ValidateReturns a read-only list of validation error messages. If the current extension configuration is valid, the list is empty. Each string describes a specific violation (e.g., missing required parameter, out-of-range value). The list is immutable and may be empty.
public static bool IsValidIndicates whether the extension configuration passes all validation rules. Returns true if no validation errors exist; otherwise false. This property is equivalent to checking whether Validate returns an empty list.
public static void EnsureValidValidates the extension configuration and throws an exception if any validation errors are present. The exception type is implementation‑specific (typically InvalidOperationException or a custom validation exception). The thrown exception includes a message that aggregates all validation errors. If the configuration is valid, the method completes without side effects.
var errors = QueryAnalysisExtensionsValidation.Validate;
if (!QueryAnalysisExtensionsValidation.IsValid)
{
Console.WriteLine("Validation failed with the following errors:");
foreach (var error in errors)
{
Console.WriteLine($" - {error}");
}
}
else
{
Console.WriteLine("Configuration is valid.");
}try
{
QueryAnalysisExtensionsValidation.EnsureValid();
// Proceed with analysis using the validated extension
RunAnalysis();
}
catch (InvalidOperationException ex)
{
Console.Error.WriteLine($"Cannot start analysis: {ex.Message}");
Environment.Exit(1);
}- The
Validatemethod andIsValidproperty are idempotent and can be called multiple times without side effects. EnsureValidis intended for guard clauses; it throws only when the configuration is invalid.- All members are static and thread‑safe. The validation state is derived from the current extension configuration, which is assumed to be immutable after initialization. Concurrent reads from multiple threads are safe.
- Edge case: if the extension configuration has not been fully initialized,
Validatemay return errors indicating missing or null parameters.IsValidwill returnfalseandEnsureValidwill throw. - The returned list from
Validateis a snapshot; it does not update automatically if the configuration changes. Re‑query the property after any modification.