ShellColumns.cs 1.0 KB

1234567891011121314151617181920212223242526272829
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using InABox.Core;
  6. namespace comal.timesheets
  7. {
  8. public class ShellColumns<TParent,TEntity> : IShellColumns<TEntity> where TEntity : Entity
  9. {
  10. private static Dictionary<string, Tuple<int,Expression<Func<TEntity, object>>>> _columns = new Dictionary<string, Tuple<int,Expression<Func<TEntity, object>>>> ();
  11. public int IndexOf(string name) => _columns[name].Item1;
  12. public Expression<Func<TEntity, object>> this[string name] => _columns[name].Item2;
  13. public ShellColumns<TParent,TEntity> Map(string property, Expression<Func<TEntity, object>> expression)
  14. {
  15. _columns[property] = new Tuple<int, Expression<Func<TEntity, object>>>(_columns.Keys.Count, expression);
  16. return this;
  17. }
  18. public Columns<TEntity> Columns => new Columns<TEntity>(_columns.Select(x => x.Value.Item2).ToArray());
  19. public int Count => _columns.Count;
  20. }
  21. }