using System.Linq.Expressions; using HopFrame.Core.Configuration; using HopFrame.Core.Helpers; namespace HopFrame.Core.Configurators; /** * The configurator for the */ public class TableConfigurator(TableConfig config) where TModel : notnull { /** The internal config that is modified */ public TableConfig Config { get; } = config; /** */ public TableConfigurator SetRoute(string route) { Config.Route = route; return this; } /** */ public TableConfigurator SetDisplayName(string displayName) { Config.DisplayName = displayName; return this; } /** */ public TableConfigurator SetDescription(string description) { Config.Description = description; return this; } /** */ public TableConfigurator 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); } /** */ public PropertyConfigurator Property(Expression> 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); } }