Added configurators
All checks were successful
HopFrame CI / build (push) Successful in 2m10s
HopFrame CI / test (push) Successful in 1m27s

This commit is contained in:
2026-02-22 19:32:33 +01:00
parent 79ed400185
commit b2a029d50b
40 changed files with 1837 additions and 1 deletions

View File

@@ -0,0 +1,59 @@
using System.Linq.Expressions;
using HopFrame.Core.Configuration;
using HopFrame.Core.Helpers;
namespace HopFrame.Core.Configurators;
/**
* The configurator for the <see cref="TableConfig"/>
*/
public class TableConfigurator<TModel>(TableConfig config) where TModel : notnull {
/** The internal config that is modified */
public TableConfig Config { get; } = config;
/** <inheritdoc cref="TableConfig.Route"/> */
public TableConfigurator<TModel> SetRoute(string route) {
Config.Route = route;
return this;
}
/** <inheritdoc cref="TableConfig.DisplayName"/> */
public TableConfigurator<TModel> SetDisplayName(string displayName) {
Config.DisplayName = displayName;
return this;
}
/** <inheritdoc cref="TableConfig.Description"/> */
public TableConfigurator<TModel> SetDescription(string description) {
Config.Description = description;
return this;
}
/** <inheritdoc cref="TableConfig.OrderIndex"/> */
public TableConfigurator<TModel> SetOrderIndex(int index) {
Config.OrderIndex = index;
return this;
}
/** Returns the configurator for a property */
public PropertyConfigurator Property(string identifier) {
var prop = Config.Properties
.FirstOrDefault(p => p.Identifier == identifier);
if (prop is null)
throw new ArgumentException($"No attribute '{identifier}' found in '{Config.Identifier}'!");
return new PropertyConfigurator(prop);
}
/** <inheritdoc cref="Property"/> */
public PropertyConfigurator Property<TProp>(Expression<Func<TModel, TProp>> propertyExpression) {
var propertyName = ExpressionHelper.GetPropertyInfo(propertyExpression).Name;
var prop = Config.Properties.FirstOrDefault(p => p.Identifier == propertyName);
if (prop is null)
throw new ArgumentException($"No attribute '{propertyName}' found in '{Config.Identifier}'!");
return new PropertyConfigurator(prop);
}
}