using System.Linq.Expressions; using System.Reflection; using TerminalUI.Controls; namespace TerminalUI.Extensions; public static class Binding { public static Binding Bind( this TView targetView, IView dataSourceView, Expression> dataContextExpression, Expression> propertyExpression, TResult? fallbackValue = default) { if (propertyExpression.Body is not MemberExpression {Member: PropertyInfo propertyInfo}) throw new AggregateException(nameof(propertyExpression) + " must be a property expression"); return new Binding( dataSourceView, dataContextExpression, targetView, propertyInfo, value => value, fallbackValue ); } public static Binding Bind( this TView targetView, IView dataSourceView, Expression> dataContextExpression, Expression> propertyExpression, Func converter, TResult? fallbackValue = default) { if (propertyExpression.Body is not MemberExpression {Member: PropertyInfo propertyInfo}) throw new AggregateException(nameof(propertyExpression) + " must be a property expression"); return new Binding( dataSourceView, dataContextExpression, targetView, propertyInfo, converter, fallbackValue ); } }