public static Expression TernaryAssign <T>(this ExpressionContainer <T> target, ExpressionContainer <bool> condition, ExpressionContainer <T> ifTrue, ExpressionContainer <T> ifFalse) { return(Expression.IfThenElse( condition.Expression, Expression.Assign(target, ifTrue), Expression.Assign(target, ifFalse))); }
/// <summary> /// Adds parameter to <see cref="BlockExpression"/> /// </summary> public BlockBuilder Parameter <T>(out ExpressionContainer <T> parameter, T value) { var expression = Expression.Parameter(typeof(T)); parameter = ExpressionShortcuts.Arg <T>(expression); return(Parameter(parameter, ExpressionShortcuts.Arg(value))); }
/// <summary> /// Adds parameter to <see cref="BlockExpression"/> /// </summary> public BlockBuilder Parameter <T>(string name, out ExpressionContainer <T> parameter, ExpressionContainer <T> value) { var expression = Expression.Parameter(typeof(T), name); parameter = ExpressionShortcuts.Arg <T>(expression); return(Parameter(parameter, value)); }
/// <summary> /// Created <see langword="return"/> statement /// </summary> /// <param name="instance"></param> /// <typeparam name="T"></typeparam> /// <returns></returns> public static IEnumerable <Expression> Return <T>(this ExpressionContainer <T> instance) { var returnTarget = Expression.Label(typeof(T)); var returnExpression = Expression.Return(returnTarget, instance, typeof(T)); var returnLabel = Expression.Label(returnTarget, Null <T>()); return(new Expression[] { returnExpression, returnLabel }); }
/// <summary> /// Creates new <see langword="case"/> expression for values specified in <paramref name="testValues"/> /// </summary> /// <param name="expression"></param> /// <param name="testValues"></param> /// <typeparam name="TR"></typeparam> /// <returns></returns> public SwitchBuilder <T, TR> Case <TR>(ExpressionContainer <TR> expression, params ExpressionContainer <T>[] testValues) { var switchBuilder = new SwitchBuilder <T, TR>(Value) { Cases = Cases, ComparerMethod = ComparerMethod, DefaultCase = DefaultCase }; return(switchBuilder.Case(expression, testValues)); }
/// <summary> /// Adds parameter to <see cref="BlockExpression"/> with initial assignment /// </summary> /// <exception cref="ArgumentException"><paramref name="expression"/> is not <see cref="ParameterExpression"/></exception> public BlockBuilder Parameter <TV>(ExpressionContainer <TV> expression, Expression value) { if (!(expression.Expression is ParameterExpression parameterExpression)) { throw new ArgumentException("is not ParameterExpression", nameof(expression)); } _parameters.Add(parameterExpression); _expressions.Add(expression.Assign(value)); return(this); }
/// <summary> /// Creates <see langword="default"/> case /// </summary> /// <param name="expression"></param> /// <typeparam name="TR"></typeparam> /// <returns></returns> public SwitchBuilder <T, TR> Default <TR>(ExpressionContainer <TR> expression) { var switchBuilder = new SwitchBuilder <T, TR>(Value) { Cases = Cases, ComparerMethod = ComparerMethod, DefaultCase = DefaultCase }; return(switchBuilder.Default(expression)); }
public static ExpressionContainer <TV> Member <T, TV>(this ExpressionContainer <T> instance, Expression <Func <T, TV> > propertyAccessor) { return(Member(instance.Expression, propertyAccessor)); }
public static SwitchBuilder <T> Switch <T>(ExpressionContainer <T> value) { return(new SwitchBuilder <T>(value)); }
/// <summary> /// Occurs in case <see cref="If(System.Linq.Expressions.Expression)"/> condition evaluated to <c>true</c> /// </summary> /// <param name="then"></param> /// <returns></returns> public ConditionBuilder Then <T>(ExpressionContainer <T> then) { _then = then.Expression; return(this); }
/// <summary> /// Adds <see langword="if"/> block /// </summary> /// <param name="condition"></param> /// <returns></returns> public ConditionBuilder If(ExpressionContainer <bool> condition) { _condition = condition; return(this); }
/// <summary> /// Adds <see langword="else"/> block /// </summary> /// <param name="then"></param> /// <returns></returns> public ConditionBuilder Else <T>(ExpressionContainer <T> then) { _else = then; return(this); }
public static ExpressionContainer Code <T>(this ExpressionContainer <T> instance, Action <T> code) { return(Call(() => code(instance))); }
public static ExpressionContainer <TV> Code <T, TV>(this ExpressionContainer <T> instance, Func <T, TV> code) { return(Call(() => code(instance))); }
/// <summary> /// Adds new "line" to <see cref="BlockExpression"/> /// </summary> public BlockBuilder Line <TV>(ExpressionContainer <TV> e) { _expressions.Add(e); return(this); }
/// <summary> /// Creates new <see langword="case"/> expression for values specified in <paramref name="testValues"/> /// </summary> /// <param name="expression"></param> /// <param name="testValues"></param> /// <returns></returns> public SwitchBuilder <T> Case(ExpressionContainer expression, params ExpressionContainer <T>[] testValues) { Cases.Add(Expression.SwitchCase(expression, testValues.Select(o => o.Expression))); return(this); }
public static ExpressionContainer Using <T>(this ExpressionContainer <T> instance, Action <ExpressionContainer <T>, BlockBuilder> blockBody) where T : IDisposable { return(Try() .Body(block => blockBody(instance, block)) .Finally(instance.Call(o => o.Dispose()))); }
public static ExpressionContainer Assign <T>(this ExpressionContainer <T> target, Expression value) { return(new ExpressionContainer(Expression.Assign(target, value))); }
public static ExpressionContainer Assign <T>(this ExpressionContainer <T> target, T value) { return(new ExpressionContainer(Expression.Assign(target, Expression.Constant(value, typeof(T))))); }
internal SwitchBuilder(ExpressionContainer <T> value) : base(Expression.Empty()) { Value = value; }
public static ExpressionContainer Call <T>(this ExpressionContainer <T> instance, Expression <Action <T> > invocationExpression) { return(new ExpressionContainer(ExpressionUtils.ProcessCallLambda(invocationExpression, instance))); }
/// <summary> /// Creates <see langword="default"/> case /// </summary> /// <param name="expression"></param> /// <returns></returns> public SwitchBuilder <T> Default(ExpressionContainer expression) { DefaultCase = expression; return(this); }
public static ExpressionContainer <TV> Call <T, TV>(this ExpressionContainer <T> instance, Expression <Func <T, TV> > invocationExpression) { return(Arg <TV>(ExpressionUtils.ProcessCallLambda(invocationExpression, instance))); }