| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- using InABox.Core;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Text;
- using System.Threading.Tasks;
- namespace InABox.Database;
- public interface IColumnUpdate
- {
- IColumn Column { get; }
- IComplexFormulaNode Update { get; }
- }
- public interface IColumnUpdate<T> : IColumnUpdate
- {
- new Column<T> Column { get; }
- IColumn IColumnUpdate.Column => Column;
- }
- public class ColumnUpdate<T, TValue> : IColumnUpdate<T>
- {
- public Column<T> Column { get; }
- public IComplexFormulaNode<T, TValue> Update { get; }
- IComplexFormulaNode IColumnUpdate.Update => Update;
- public ColumnUpdate(Expression<Func<T, TValue>> column, IComplexFormulaNode<T, TValue> update)
- {
- Column = new(CoreUtils.GetFullPropertyName(column));
- Update = update;
- }
- }
- public interface IColumnUpdates
- {
- IEnumerable<IColumnUpdate> Updates();
- }
- public class ColumnUpdates<T> : List<IColumnUpdate<T>>, IColumnUpdates
- {
- public IEnumerable<IColumnUpdate> Updates() => this;
- public ColumnUpdates<T> Add<TValue>(Expression<Func<T, TValue>> column, IComplexFormulaNode<T, TValue> update)
- {
- Add(new ColumnUpdate<T, TValue>(column, update));
- return this;
- }
- public ColumnUpdates<T> Add<TValue>(Expression<Func<T, TValue>> column, Func<IComplexFormulaGenerator<T, TValue>, IComplexFormulaNode<T, TValue>> update)
- {
- Add(new ColumnUpdate<T, TValue>(column, update(IComplexFormulaGenerator.Create<T, TValue>())));
- return this;
- }
- public ColumnUpdates<T> AddProperty<TValue>(Expression<Func<T, TValue>> column, Expression<Func<T, TValue>> field)
- {
- Add(new ColumnUpdate<T, TValue>(column, ComplexFormulaGenerator.Property(field)));
- return this;
- }
- public ColumnUpdates<T> AddConstant<TValue>(Expression<Func<T, TValue>> column, TValue constant)
- {
- Add(new ColumnUpdate<T, TValue>(column, ComplexFormulaGenerator.Constant<T, TValue>(constant)));
- return this;
- }
- }
|