/// <summary> /// Instantiates an expression to expression slim converter with a given typespace and slim expression factory. /// </summary> /// <param name="typeSpace">The type space.</param> /// <param name="factory">The slim expression factory.</param> public ExpressionToExpressionSlimConverter(TypeSpace typeSpace, IExpressionSlimFactory factory) { TypeSpace = typeSpace ?? throw new ArgumentNullException(nameof(typeSpace)); _factory = factory ?? throw new ArgumentNullException(nameof(factory)); _parameters = new Dictionary <ParameterExpression, ParameterExpressionSlim>(); _labels = new Dictionary <LabelTarget, LabelTargetSlim>(); }
/// <summary> /// Converts the specified expression to a lightweight representation using the specified expression factory. /// </summary> /// <param name="expression">Expression to convert.</param> /// <param name="factory">The expression factory to use.</param> /// <returns>Lightweight representation of the specified expression.</returns> public static ExpressionSlim ToExpressionSlim(this Expression expression, IExpressionSlimFactory factory) { if (expression == null) { throw new ArgumentNullException(nameof(expression)); } if (factory == null) { throw new ArgumentNullException(nameof(factory)); } return(new ExpressionToExpressionSlimConverter(new TypeSpace(), factory).Visit(expression)); }