/// <summary> /// Creates catch block for exception of any type. /// </summary> /// <param name="catchExpression">Catch expression.</param> public CatchBlock(Expression catchExpression) { Validators.NullCheck(catchExpression, "catchExpression"); ExceptionType = typeof(object); _preCatchExpression = new ExceptionCatchInitializerExpression(ExceptionType, null, false); _catchExpression = ExprHelper.PopIfNeeded(catchExpression); }
public IfThenExpression(Expression predicate, Expression thenExpression) { Validators.NullCheck(predicate, "predicate"); Validators.NullCheck(thenExpression, "thenExpression"); Validators.PrimitiveOrReferenceType(predicate.ExpressionType, "predicate"); _predicate = predicate; _thenExpression = ExprHelper.PopIfNeeded(thenExpression); }
public BlockExpression(Expression[] expressions) { Validators.NullCollectionElementsCheck(expressions, "expressions"); _expressions = new Expression[expressions.Length]; for (int i = 0; i < expressions.Length; i++) { _expressions[i] = ExprHelper.PopIfNeeded(expressions[i]); } }
/// <summary> /// Creates catch block for exception of exceptionType, where exception instance is not required. /// </summary> /// <param name="exceptionType">Exception type.</param> /// <param name="catchExpression">Catch expression.</param> public CatchBlock(Type exceptionType, Expression catchExpression) { Validators.NullCheck(exceptionType, "exceptionType"); Validators.NullCheck(catchExpression, "catchExpression"); Validators.HierarchyCheck(exceptionType, typeof(Exception), "Provided type {0} has to be deriving from {1}", "exceptionType"); ExceptionType = exceptionType; _preCatchExpression = new ExceptionCatchInitializerExpression(exceptionType, null, false); _catchExpression = ExprHelper.PopIfNeeded(catchExpression); }
public MethodBodyBuilder AddStatement(Expression expression) { if (expression == null) { throw new ArgumentNullException("expression"); } _statements.Add(ExprHelper.PopIfNeeded(expression)); return(this); }
/// <summary> /// Creates catch block for exception of exceptionType. /// Exception instance would be available through exceptionVariable, which could be used in catchExpression. /// </summary> /// <param name="exceptionType">Exception type.</param> /// <param name="exceptionVariable">Variable used to access caught exception</param> /// <param name="declareVariable">If true, exception variable would be declared before use</param> /// <param name="catchExpression">Catch expression.</param> public CatchBlock(Type exceptionType, LocalVariable exceptionVariable, bool declareVariable, Expression catchExpression) { Validators.NullCheck(exceptionType, "exceptionType"); Validators.NullCheck(catchExpression, "catchExpression"); Validators.NullCheck(exceptionVariable, "exceptionVariable"); Validators.HierarchyCheck(exceptionType, typeof(Exception), "Provided type {0} has to be deriving from {1}", "exceptionType"); Validators.HierarchyCheck(exceptionType, exceptionVariable.VariableType, "Unable to assign exception of type {0} to local of type {1}", "exceptionVariable"); ExceptionType = exceptionType; _exceptionVariable = exceptionVariable; _preCatchExpression = new ExceptionCatchInitializerExpression(exceptionType, exceptionVariable, declareVariable); _catchExpression = ExprHelper.PopIfNeeded(catchExpression); }
internal ValueBlockExpression(Type valueType, Expression[] expressions) : base(valueType) { Validators.NullCollectionElementsCheck(expressions, "expressions"); ValidateResultType(valueType, expressions); _expressions = new Expression[expressions.Length]; for (int i = 0; i < expressions.Length; i++) { _expressions[i] = (i + 1 < expressions.Length) ? ExprHelper.PopIfNeeded(expressions[i]) : expressions[i]; } }
public TryCatchFinallyExpression(Expression tryExpression, Expression finallyExpression, params CatchBlock[] catchBlocks) { Validators.NullCheck(tryExpression, "tryExpression"); Validators.NullCollectionElementsCheck(catchBlocks, "catchBlocks"); if (catchBlocks.Length == 0 && finallyExpression == null) { throw new ArgumentException("Try-Catch-Finally block has to have finally block or at least one catch block"); } ValidateOrderOfCatchBlocks(catchBlocks); _tryExpression = ExprHelper.PopIfNeeded(tryExpression); if (finallyExpression != null) { _finallyExpression = ExprHelper.PopIfNeeded(finallyExpression); } _catchBlocks = catchBlocks; }
public LoopExpression(Expression loop) { Validators.NullCheck(loop, "loop"); _loop = ExprHelper.PopIfNeeded(loop); }