From 31d1d9d171243a7178042e15c38e7feb27e22b55 Mon Sep 17 00:00:00 2001 From: TekH Date: Wed, 10 Dec 2025 13:43:58 +0100 Subject: [PATCH] Add EnsureProperties for attribute-based config validation Added EnsureProperties() to EntityBaseOptions, enabling automatic validation of required properties marked with MustConfiguredAttribute via reflection. This reduces manual configuration and improves maintainability. --- .../Options/Shared/EntityBaseOptions.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/ReC.Infrastructure/Options/Shared/EntityBaseOptions.cs b/src/ReC.Infrastructure/Options/Shared/EntityBaseOptions.cs index d0b8e7c..74b0188 100644 --- a/src/ReC.Infrastructure/Options/Shared/EntityBaseOptions.cs +++ b/src/ReC.Infrastructure/Options/Shared/EntityBaseOptions.cs @@ -1,4 +1,6 @@ -namespace ReC.Infrastructure.Options.Shared; +using ReC.Domain.Attributes; + +namespace ReC.Infrastructure.Options.Shared; public record EntityBaseOptions() { @@ -13,5 +15,14 @@ public record EntityBaseOptions() } public void EnsureProperties(params string[] propertyNames) - => EnsureProperties(propertyNames.AsEnumerable()); + => EnsureProperties(propertyNames.AsEnumerable()); + + public void EnsureProperties() + { + var propertyNames = typeof(T) + .GetProperties() + .Where(prop => Attribute.IsDefined(prop, typeof(MustConfiguredAttribute))) + .Select(prop => prop.Name); + EnsureProperties(propertyNames); + } } \ No newline at end of file