Add EnsureProperties<T> for attribute-based config validation

Added EnsureProperties<T>() to EntityBaseOptions, enabling automatic validation of required properties marked with MustConfiguredAttribute via reflection. This reduces manual configuration and improves maintainability.
This commit is contained in:
2025-12-10 13:43:58 +01:00
parent 1419455b36
commit 31d1d9d171

View File

@@ -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<T>()
{
var propertyNames = typeof(T)
.GetProperties()
.Where(prop => Attribute.IsDefined(prop, typeof(MustConfiguredAttribute)))
.Select(prop => prop.Name);
EnsureProperties(propertyNames);
}
}