<commit_before>﻿using System;
using System.IO;
using System.Linq;
using System.Linq.Expressions;

namespace Handlebars.Compiler
{
    internal class ContextBinder : HandlebarsExpressionVisitor
    {
        public static Expression Bind(Expression body, CompilationContext context, Expression parentContext)
        {
            var writerParameter = Expression.Parameter(typeof(TextWriter));
            var objectParameter = Expression.Parameter(typeof(object));
            if (parentContext == null)
            {
                parentContext = Expression.Constant(null, typeof(BindingContext));
            }
            var bindingContext = Expression.New(
                 typeof(BindingContext).GetConstructor(
                     new[] { typeof(object), typeof(TextWriter), typeof(BindingContext) }),
                new Expression[] { objectParameter, Expression.Call(new Func<TextWriter, TextWriter>(GetEncodedWriter).Method,writerParameter), parentContext });
            return Expression.Lambda<Action<TextWriter, object>>(
                Expression.Block(
                    new [] { context.BindingContext },
                    new Expression[] {
                        Expression.IfThenElse(
                            Expression.TypeIs(objectParameter, typeof(BindingContext)),
                            Expression.Assign(context.BindingContext, Expression.TypeAs(objectParameter, typeof(BindingContext))),
                            Expression.Assign(context.BindingContext, bindingContext))
                    }.Concat(
                        ((BlockExpression)body).Expressions
                    )),
                new[] { writerParameter, objectParameter });
        }

        private static TextWriter GetEncodedWriter(TextWriter writer)
        {
            if(typeof(EncodedTextWriter).IsAssignableFrom(writer.GetType()))
            {
                return writer;
            }
            else
            {
                return new EncodedTextWriter(writer);
            }
        }
    }
}<commit_msg>Clearer ctor expr variable name<commit_after>﻿using System;
using System.IO;
using System.Linq;
using System.Linq.Expressions;

namespace Handlebars.Compiler
{
    internal class ContextBinder : HandlebarsExpressionVisitor
    {
        public static Expression Bind(Expression body, CompilationContext context, Expression parentContext)
        {
            var writerParameter = Expression.Parameter(typeof(TextWriter));
            var objectParameter = Expression.Parameter(typeof(object));
            if (parentContext == null)
            {
                parentContext = Expression.Constant(null, typeof(BindingContext));
            }
            var newBindingContext = Expression.New(
                 typeof(BindingContext).GetConstructor(
                     new[] { typeof(object), typeof(TextWriter), typeof(BindingContext) }),
                new Expression[] { objectParameter, Expression.Call(new Func<TextWriter, TextWriter>(GetEncodedWriter).Method,writerParameter), parentContext });
            return Expression.Lambda<Action<TextWriter, object>>(
                Expression.Block(
                    new [] { context.BindingContext },
                    new Expression[] {
                        Expression.IfThenElse(
                            Expression.TypeIs(objectParameter, typeof(BindingContext)),
                            Expression.Assign(context.BindingContext, Expression.TypeAs(objectParameter, typeof(BindingContext))),
                            Expression.Assign(context.BindingContext, newBindingContext))
                    }.Concat(
                        ((BlockExpression)body).Expressions
                    )),
                new[] { writerParameter, objectParameter });
        }

        private static TextWriter GetEncodedWriter(TextWriter writer)
        {
            if(typeof(EncodedTextWriter).IsAssignableFrom(writer.GetType()))
            {
                return writer;
            }
            else
            {
                return new EncodedTextWriter(writer);
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.08527131782945736, 'fraction_numerical': 0.0, 'mean_word_length': 1.926293408929837, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5629030', 'n_tokens_mistral': 901, 'n_tokens_neox': 871, 'n_words': 170}