예제 #1
0
        /// <summary>
        /// Implementation of <see cref="IExpressionGenerator.GenerateExpression"/>. Calls
        /// <see cref="CreateExpression"/> and raises the <see cref="ExpressionGenerated"/> event
        /// </summary>
        /// <param name="type">
        /// The type.
        /// </param>
        /// <returns>
        /// A <see cref="System.Linq.Expressions.Expression"/> that when evaluated 
        /// will return an instance of the given type, taking into account any
        /// event handlers that may have modified the expression
        /// </returns>
        public Expression GenerateExpression(Type type)
        {
            var expression = this.CreateExpression(type);
            var args = new ExpressionGeneratedEventArgs(type, expression);
            this.OnExpressionGenerated(args);
            while (args.Expression.CanReduce)
            {
                args.Expression = args.Expression.Reduce();
            }

            return args.Expression;
        }
예제 #2
0
 /// <summary>
 /// Raises the <see cref="ExpressionGenerated"/> event.
 /// </summary>
 /// <param name="args">
 /// The event args for this event.
 /// </param>
 protected virtual void OnExpressionGenerated(ExpressionGeneratedEventArgs args)
 {
     var handler = this.ExpressionGenerated;
     handler(this, args);
 }