release orchestrator v1 draft and build fixes
This commit is contained in:
35
src/Plugin/StellaOps.Plugin.Sdk/PluginOptionsBase.cs
Normal file
35
src/Plugin/StellaOps.Plugin.Sdk/PluginOptionsBase.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
namespace StellaOps.Plugin.Sdk;
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
/// <summary>
|
||||
/// Options base class with validation support.
|
||||
/// </summary>
|
||||
public abstract class PluginOptionsBase : IValidatableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Override to add custom validation logic.
|
||||
/// </summary>
|
||||
/// <param name="validationContext">Validation context.</param>
|
||||
/// <returns>Validation results.</returns>
|
||||
public virtual IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the options and throws if invalid.
|
||||
/// </summary>
|
||||
/// <exception cref="ValidationException">If validation fails.</exception>
|
||||
public void ValidateAndThrow()
|
||||
{
|
||||
var context = new ValidationContext(this);
|
||||
var results = new List<ValidationResult>();
|
||||
|
||||
if (!Validator.TryValidateObject(this, context, results, validateAllProperties: true))
|
||||
{
|
||||
var errors = string.Join(", ", results.Select(r => r.ErrorMessage));
|
||||
throw new ValidationException($"Configuration validation failed: {errors}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user