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:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user