public ExpressionWithSource(Expression expression, ExpressionSourceType source)
 {
     Expression = expression;
     Source = source;
 }
 private Task<string> GenerateTextAsync(Expression expression, ExpressionSourceType source)
 {
     return Task.Run(() => GenerateText(expression, source));
 }
 private Task<string> GenerateTextAsync(Expression expression, ExpressionSourceType source, CancellationToken cancellationToken)
 {
     return Task.Run(() =>
     {
         try
         {
             using (cancellationToken.Register(System.Threading.Thread.CurrentThread.Abort))
             {
                 return GenerateText(expression, source);
             }
         }
         catch (ThreadAbortException)
         {
             throw;
         }
     }, cancellationToken);
 }
        private string GenerateText(Expression expression, ExpressionSourceType source)
        {
            IGenerator template = GeneratorFactory.CreateGenerator(_type, _ruleSetValidator);

            //TODO: can most likely remove this templateInitialization and replace with constructor in partial class
            var templateInitialization = new Dictionary<string, object>
            {
                {"objectExpression", expression},
                {"maxDepth", _maxDepth},
            };

            template.Session = templateInitialization;

            //Set the conversion source
            if (source == ExpressionSourceType.Locals)
            {
                template.Converter = _localsConverter;
            }
            else
            {
                template.Converter = _customExpressionConverter;
            }

            template.Initialize();
            template.Clear();

            string transformedText = template.TransformText();

            return transformedText;
        }