<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using StructureMap.Diagnostics;
using StructureMap.Pipeline;
using StructureMap.TypeRules;

namespace StructureMap.Building
{
    public class ConcreteBuild : IHasSetters, IDependencySource, IBuildPlanVisitable
    {
        private readonly Type _concreteType;
        private readonly ConstructorStep _constructor;
        private readonly IList<Setter> _setters = new List<Setter>();

        public ConcreteBuild(Type concreteType) : this(concreteType, new ConstructorSelector().Select(concreteType))
        {
        }

        public ConcreteBuild(Type concreteType, ConstructorStep constructor)
        {
            _concreteType = concreteType;
            _constructor = constructor;
        }

        protected ConcreteBuild(Type concreteType, ConstructorInfo constructor)
            : this(concreteType, new ConstructorStep(constructor))
        {
        }


        public Type ConcreteType
        {
            get { return _concreteType; }
        }

        public void Add(Setter setter)
        {
            _setters.Add(setter);
        }

        public void Add(Type setterType, MemberInfo member, IDependencySource value)
        {
            _setters.Add(new Setter(setterType, member, value));
        }

        public ConstructorStep Constructor
        {
            get { return _constructor; }
        }

        public object Build(IBuildSession session, IContext context)
        {
            var @delegate = ToDelegate() as Func<IBuildSession, IContext, object>;

            return @delegate(session, context);
        }

        public T Build<T>(IBuildSession session) where T : class
        {
            return Build(session, session.As<IContext>()) as T;
        }

        public string Description
        {
            get
            {
                var args = _constructor.Arguments.Select(x => x.Dependency.Description).ToArray();

                var description = "new {0}({1})".ToFormat(_concreteType.Name, string.Join(", ", args));

                if (_setters.Any())
                {
                    description += "{";<commit_msg>Adding null check to avoid null dereference error<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using StructureMap.Diagnostics;
using StructureMap.Pipeline;
using StructureMap.TypeRules;

namespace StructureMap.Building
{
    public class ConcreteBuild : IHasSetters, IDependencySource, IBuildPlanVisitable
    {
        private readonly Type _concreteType;
        private readonly ConstructorStep _constructor;
        private readonly IList<Setter> _setters = new List<Setter>();

        public ConcreteBuild(Type concreteType) : this(concreteType, new ConstructorSelector().Select(concreteType))
        {
        }

        public ConcreteBuild(Type concreteType, ConstructorStep constructor)
        {
            _concreteType = concreteType;
            _constructor = constructor;
        }

        protected ConcreteBuild(Type concreteType, ConstructorInfo constructor)
            : this(concreteType, new ConstructorStep(constructor))
        {
        }


        public Type ConcreteType
        {
            get { return _concreteType; }
        }

        public void Add(Setter setter)
        {
            _setters.Add(setter);
        }

        public void Add(Type setterType, MemberInfo member, IDependencySource value)
        {
            _setters.Add(new Setter(setterType, member, value));
        }

        public ConstructorStep Constructor
        {
            get { return _constructor; }
        }

        public object Build(IBuildSession session, IContext context)
        {
            var @delegate = ToDelegate() as Func<IBuildSession, IContext, object>;

            return @delegate != null ? @delegate(session, context) : null;
        }

        public T Build<T>(IBuildSession session) where T : class
        {
            return Build(session, session.As<IContext>()) as T;
        }

        public string Description
        {
            get
            {
                var args = _constructor.Arguments.Select(x => x.Dependency.Description).ToArray();

                var description = "new {0}({1})".ToFormat(_concreteType.Name, string.Join(", ", args));

                if (_setters.Any())
                {
                    description += "{";
{'fraction_non_alphanumeric': 0.08313120176405733, 'fraction_numerical': 0.0008820286659316428, 'mean_word_length': 2.1853932584269664, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, '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': '4321481', 'n_tokens_mistral': 1172, 'n_tokens_neox': 1118, 'n_words': 280}