| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Expressions;
- using InABox.Core;
- namespace InABox.Avalonia
- {
- public class ShellColumn<TEntity>
- where TEntity : Entity
- {
- public int Index { get; }
- public Expression<Func<TEntity, object?>> Expression { get; }
- public string ColumnName { get; }
- public ShellColumn(int index, Expression<Func<TEntity, object?>> expression)
- {
- Index = index;
- Expression = expression;
- ColumnName = CoreUtils.GetFullPropertyName(expression, ".");
- }
- }
- public class ShellColumns<TParent,TEntity> : IShellColumns<TEntity> where TEntity : Entity
- {
-
- private static Dictionary<string, ShellColumn<TEntity>> _columns = new();
- public int IndexOf(string name) => _columns[name].Index;
-
- public string this[string name] => _columns[name].ColumnName;
- public ShellColumns<TParent,TEntity> Map(string property, Expression<Func<TEntity, object?>> expression)
- {
- int iCol = _columns.Keys.Count;
- if(_columns.TryGetValue(property, out var column))
- {
- iCol = column.Index;
- }
-
- _columns[property] = new(iCol, expression);
- return this;
- }
- public string? FindShellProperty(string entityProperty)
- {
- foreach(var (property, column) in _columns)
- {
- if(column.ColumnName == entityProperty)
- {
- return property;
- }
- }
- return null;
- }
- public Columns<TEntity> Columns => new Columns<TEntity>(ColumnTypeFlags.None).Add(_columns.Select(x => x.Value.ColumnName));
-
- public int Count => _columns.Count;
- }
- }
|