<commit_before>using System;
using System.Reflection;
using FluentNHibernate;
using FluentNHibernate.Mapping;

namespace FluentNHibernate.AutoMap
{
    public class AutoPersistenceModel : PersistenceModel
    {
        private readonly AutoMapper autoMap;
        private Assembly assemblyContainingMaps;
        private Func<Type, bool> shouldIncludeType = t => true;
        private Assembly entityAssembly;

        public ConventionBuilder WithConvention
        {
            get { return new ConventionBuilder(this); }
        }

        public static AutoPersistenceModel MapEntitiesFromAssemblyOf<T>()
        {
            var persistenceModel = new AutoPersistenceModel();
            persistenceModel.AddEntityAssembly(Assembly.GetAssembly(typeof (T)));
            return persistenceModel;
        }

        public AutoPersistenceModel Where(Func<Type, bool> shouldIncludeType)
        {
            this.shouldIncludeType = shouldIncludeType;
            return this;
        }

        public AutoPersistenceModel MergeWithAutoMapsFromAssemblyOf<T>()
        {
            assemblyContainingMaps = Assembly.GetAssembly(typeof (T));
            return this;
        }

        public override void Configure(NHibernate.Cfg.Configuration configuration)
        {
            if (assemblyContainingMaps != null)
                addMappingsFromAssembly(assemblyContainingMaps);

            foreach (var obj in entityAssembly.GetTypes())
            {
                if (obj.IsClass)
                {
                    if (shouldIncludeType.Invoke(obj))
                    {
                        // Find the map that already exists
                        var findMapMethod = typeof (AutoPersistenceModel).GetMethod("FindMapping");
                        var genericFindMapMethod = findMapMethod.MakeGenericMethod(obj);
                        var mapping = genericFindMapMethod.Invoke(this, null);

                        if (mapping != null)
                        {
                            // Merge Mappings together
                            var findAutoMapMethod = typeof (AutoMapper).GetMethod("MergeMap");
                            var genericfindAutoMapMethod = findAutoMapMethod.MakeGenericMethod(obj);
                            genericfindAutoMapMethod.Invoke(autoMap, new[] {mapping});
                        }
                        else
                        {
                            //Auto magically map the entity
                            var findAutoMapMethod = typeof (AutoMapper).GetMethod("Map", new Type[0]);
                            var genericfindAutoMapMethod = findAutoMapMethod.MakeGenericMethod(obj);<commit_msg>Fixed bug in detecting classes to automap.<commit_after>using System;
using System.Reflection;
using FluentNHibernate;
using FluentNHibernate.Mapping;

namespace FluentNHibernate.AutoMap
{
    public class AutoPersistenceModel : PersistenceModel
    {
        private readonly AutoMapper autoMap;
        private Assembly assemblyContainingMaps;
        private Func<Type, bool> shouldIncludeType = t => true;
        private Assembly entityAssembly;

        public ConventionBuilder WithConvention
        {
            get { return new ConventionBuilder(this); }
        }

        public static AutoPersistenceModel MapEntitiesFromAssemblyOf<T>()
        {
            var persistenceModel = new AutoPersistenceModel();
            persistenceModel.AddEntityAssembly(Assembly.GetAssembly(typeof (T)));
            return persistenceModel;
        }

        public AutoPersistenceModel Where(Func<Type, bool> shouldIncludeType)
        {
            this.shouldIncludeType = shouldIncludeType;
            return this;
        }

        public AutoPersistenceModel MergeWithAutoMapsFromAssemblyOf<T>()
        {
            assemblyContainingMaps = Assembly.GetAssembly(typeof (T));
            return this;
        }

        public override void Configure(NHibernate.Cfg.Configuration configuration)
        {
            if (assemblyContainingMaps != null)
                addMappingsFromAssembly(assemblyContainingMaps);

            foreach (var obj in entityAssembly.GetTypes())
            {
		if (obj.IsClass && obj.BaseType == typeof(object))
                {
                    if (shouldIncludeType.Invoke(obj))
                    {
                        // Find the map that already exists
                        var findMapMethod = typeof (AutoPersistenceModel).GetMethod("FindMapping");
                        var genericFindMapMethod = findMapMethod.MakeGenericMethod(obj);
                        var mapping = genericFindMapMethod.Invoke(this, null);

                        if (mapping != null)
                        {
                            // Merge Mappings together
                            var findAutoMapMethod = typeof (AutoMapper).GetMethod("MergeMap");
                            var genericfindAutoMapMethod = findAutoMapMethod.MakeGenericMethod(obj);
                            genericfindAutoMapMethod.Invoke(autoMap, new[] {mapping});
                        }
                        else
                        {
                            //Auto magically map the entity
                            var findAutoMapMethod = typeof (AutoMapper).GetMethod("Map", new Type[0]);
                            var genericfindAutoMapMethod = findAutoMapMethod.MakeGenericMethod(obj);
{'fraction_non_alphanumeric': 0.06643292120317401, 'fraction_numerical': 0.0003690717844620779, 'mean_word_length': 1.7526663280853225, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '3744517', 'n_tokens_mistral': 1226, 'n_tokens_neox': 1164, 'n_words': 271}