using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Linq.Expressions; using System.Text; namespace InABox.Core { public class CoreGridColumn { public IProperty Property { get; set; } public int Width { get; set; } public Alignment Alignment { get; set; } public string Format { get; set; } public BaseEditor Editor { get; set; } public string Caption { get; set; } public CoreGridColumn(IProperty property, int width, Alignment alignment, string format, BaseEditor editor, string caption) { Property = property; Width = width; Alignment = alignment; Format = format; Editor = editor; Caption = caption; } } /// /// This is the new system for managing default columns on grids. (This replaces on ). /// public static class DefaultColumns { private static readonly Dictionary> _columns = new Dictionary>(); public static IEnumerable GetDefaultColumns(Type T) { System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(T.TypeHandle); return _columns.GetValueOrDefault(T) ?? Enumerable.Empty(); } public static CoreGridColumn CreateColumn( Expression> member, int? width = null, string? caption = null, string? format = null, Alignment? alignment = null) { var prop = DatabaseSchema.Property(member) ?? throw new Exception($"Could not find property {CoreUtils.GetFullPropertyName(member, ".")}"); var col = new CoreGridColumn( prop, width ?? prop.Editor.Width, alignment ?? prop.Editor.Alignment, format ?? prop.Editor.Format, prop.Editor.CloneEditor(), caption ?? prop.Caption); return col; } public static CoreGridColumn Add( Expression> member, int? width = null, string? caption = null, string? format = null, Alignment? alignment = null ) { var col = CreateColumn(member, width: width, caption: caption, format: format, alignment: alignment); var list = _columns.GetValueOrAdd(typeof(TType)); list.Add(col); return col; } } }