|
|
@@ -6,35 +6,57 @@ 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, Tuple<int,Expression<Func<TEntity, object?>>>> _columns = new Dictionary<string, Tuple<int,Expression<Func<TEntity, object?>>>> ();
|
|
|
+ private static Dictionary<string, ShellColumn<TEntity>> _columns = new();
|
|
|
|
|
|
- public int IndexOf(string name) => _columns[name].Item1;
|
|
|
+ public int IndexOf(string name) => _columns[name].Index;
|
|
|
|
|
|
- public Expression<Func<TEntity, object?>> this[string name] => _columns[name].Item2;
|
|
|
+ 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;
|
|
|
- bool bFound = _columns.TryGetValue(property, out var column);
|
|
|
- try
|
|
|
+ if(_columns.TryGetValue(property, out var column))
|
|
|
{
|
|
|
- if (bFound)
|
|
|
- iCol = column.Item1;
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
-
|
|
|
+ iCol = column.Index;
|
|
|
}
|
|
|
|
|
|
- _columns[property] = new Tuple<int, Expression<Func<TEntity, object?>>>(iCol, expression);
|
|
|
- //_columns[property] = new Tuple<int, Expression<Func<TEntity, object>>>(_columns.Keys.Count, expression);
|
|
|
+ _columns[property] = new(iCol, expression);
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- public Columns<TEntity> Columns => new Columns<TEntity>(ColumnTypeFlags.None).Add(_columns.Select(x => x.Value.Item2).ToArray());
|
|
|
+ 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;
|
|
|
|