Пример #1
0
 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)));
 }
Пример #2
0
        /// <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)));
        }
Пример #3
0
        /// <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));
        }
Пример #4
0
        /// <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 });
        }
Пример #5
0
        /// <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));
        }
Пример #6
0
        /// <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);
        }
Пример #7
0
        /// <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));
        }
Пример #8
0
 public static ExpressionContainer <TV> Member <T, TV>(this ExpressionContainer <T> instance, Expression <Func <T, TV> > propertyAccessor)
 {
     return(Member(instance.Expression, propertyAccessor));
 }
Пример #9
0
 public static SwitchBuilder <T> Switch <T>(ExpressionContainer <T> value)
 {
     return(new SwitchBuilder <T>(value));
 }
Пример #10
0
        /// <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);
        }
Пример #11
0
        /// <summary>
        /// Adds <see langword="if"/> block
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public ConditionBuilder If(ExpressionContainer <bool> condition)
        {
            _condition = condition;

            return(this);
        }
Пример #12
0
 /// <summary>
 /// Adds <see langword="else"/> block
 /// </summary>
 /// <param name="then"></param>
 /// <returns></returns>
 public ConditionBuilder Else <T>(ExpressionContainer <T> then)
 {
     _else = then;
     return(this);
 }
Пример #13
0
 public static ExpressionContainer Code <T>(this ExpressionContainer <T> instance, Action <T> code)
 {
     return(Call(() => code(instance)));
 }
Пример #14
0
 public static ExpressionContainer <TV> Code <T, TV>(this ExpressionContainer <T> instance, Func <T, TV> code)
 {
     return(Call(() => code(instance)));
 }
Пример #15
0
 /// <summary>
 /// Adds new "line" to <see cref="BlockExpression"/>
 /// </summary>
 public BlockBuilder Line <TV>(ExpressionContainer <TV> e)
 {
     _expressions.Add(e);
     return(this);
 }
Пример #16
0
        /// <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);
        }
Пример #17
0
 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())));
 }
Пример #18
0
 public static ExpressionContainer Assign <T>(this ExpressionContainer <T> target, Expression value)
 {
     return(new ExpressionContainer(Expression.Assign(target, value)));
 }
Пример #19
0
 public static ExpressionContainer Assign <T>(this ExpressionContainer <T> target, T value)
 {
     return(new ExpressionContainer(Expression.Assign(target, Expression.Constant(value, typeof(T)))));
 }
Пример #20
0
 internal SwitchBuilder(ExpressionContainer <T> value) : base(Expression.Empty())
 {
     Value = value;
 }
Пример #21
0
 public static ExpressionContainer Call <T>(this ExpressionContainer <T> instance, Expression <Action <T> > invocationExpression)
 {
     return(new ExpressionContainer(ExpressionUtils.ProcessCallLambda(invocationExpression, instance)));
 }
Пример #22
0
 /// <summary>
 /// Creates <see langword="default"/> case
 /// </summary>
 /// <param name="expression"></param>
 /// <returns></returns>
 public SwitchBuilder <T> Default(ExpressionContainer expression)
 {
     DefaultCase = expression;
     return(this);
 }
Пример #23
0
 public static ExpressionContainer <TV> Call <T, TV>(this ExpressionContainer <T> instance, Expression <Func <T, TV> > invocationExpression)
 {
     return(Arg <TV>(ExpressionUtils.ProcessCallLambda(invocationExpression, instance)));
 }