<commit_before>﻿using SSystem.Data.Mappings;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace SSystem.Data
{
    public partial class Database
    {
        private void AssignValue<T>(IDataReader reader, IEnumerable<string> allFieldNames, PropertyInfo propertyInfo, T target)
        {
            if (reader == null)
                throw new ArgumentNullException(nameof(reader));
            if (propertyInfo == null)
                throw new ArgumentNullException(nameof(propertyInfo));
            if (target == null)
                throw new ArgumentNullException(nameof(target));

            string col = propertyInfo.Name;
            var attr = propertyInfo.GetCustomAttribute(typeof(ColumnAttribute)) as ColumnAttribute;
            if (attr != null && !string.IsNullOrEmpty(attr.ColumnName))
            {
                col = attr.ColumnName;
            }

            if(allFieldNames.Where(a=>a.Equals(col,StringComparison.InvariantCultureIgnoreCase)).Any())
            {
                var index = reader.GetOrdinal(col);
                var value = reader.GetValue(index);
                if (value == DBNull.Value)
                {
                    value = null;
                }

                if (index > -1)
                {
                    propertyInfo.SetValue(target, value);
                }
            }

        }

        private IDbConnection CreateConnection(string connectionString)
        {
            if (m_DbProviderFactory == null)
            {
                m_DbProviderFactory = CreateDbProviderFactory();
            }
            IDbConnection icon = m_DbProviderFactory.CreateConnection();
            icon.ConnectionString = connectionString;
            return icon;
        }

        private DbProviderFactory CreateDbProviderFactory() => DbProviderFactories.GetFactory(m_ProviderName);

        private string ReplaceProfixTag(string sql)
        {
            if (string.IsNullOrEmpty(sql))
                return sql;
            sql = sql.Replace("@", TagName);
            return sql;
        }

        private IEnumerable<string> GetNames(IDataReader reader)
        {
            var names = new List<string>();
            int count = reader.FieldCount;
            for (int i = 0; i < count; i++)
            {
                names.Add(reader.GetName(i));
            }
            return names;
        }
    }
}
<commit_msg>处理枚举类型<commit_after>﻿using SSystem.Data.Mappings;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace SSystem.Data
{
    public partial class Database
    {
        private void AssignValue<T>(IDataReader reader, IEnumerable<string> allFieldNames, PropertyInfo propertyInfo, T target)
        {
            if (reader == null)
                throw new ArgumentNullException(nameof(reader));
            if (propertyInfo == null)
                throw new ArgumentNullException(nameof(propertyInfo));
            if (target == null)
                throw new ArgumentNullException(nameof(target));

            string col = propertyInfo.Name;
            var attr = propertyInfo.GetCustomAttribute(typeof(ColumnAttribute)) as ColumnAttribute;
            if (attr != null && !string.IsNullOrEmpty(attr.ColumnName))
            {
                col = attr.ColumnName;
            }

            if (allFieldNames.Where(a => a.Equals(col, StringComparison.InvariantCultureIgnoreCase)).Any())
            {
                var index = reader.GetOrdinal(col);
                var value = reader.GetValue(index);
                if (value == DBNull.Value)
                {
                    value = null;
                }

                if (index > -1)
                {
                    //propertyInfo.PropertyType.BaseType.Name
                    if (propertyInfo.PropertyType.IsEnum)
                    {

                        propertyInfo.SetValue(target, Enum.ToObject(propertyInfo.PropertyType, value));
                    }
                    else
                    {
                        propertyInfo.SetValue(target, value);
                    }
                }
            }

        }

        private IDbConnection CreateConnection(string connectionString)
        {
            if (m_DbProviderFactory == null)
            {
                m_DbProviderFactory = CreateDbProviderFactory();
            }
            IDbConnection icon = m_DbProviderFactory.CreateConnection();
            icon.ConnectionString = connectionString;
            return icon;
        }

        private DbProviderFactory CreateDbProviderFactory() => DbProviderFactories.GetFactory(m_ProviderName);

        private string ReplaceProfixTag(string sql)
        {
            if (string.IsNullOrEmpty(sql))
                return sql;
            sql = sql.Replace("@", TagName);
            return sql;
        }

        private IEnumerable<string> GetNames(IDataReader reader)
        {
            var names = new List<string>();
            int count = reader.FieldCount;
            for (int i = 0; i < count; i++)
            {
                names.Add(reader.GetName(i));
            }
            return names;
        }
    }
}

{'fraction_non_alphanumeric': 0.0868049183336392, 'fraction_numerical': 0.0007340796476417691, 'mean_word_length': 1.636671504596033, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, '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': '5655931', 'n_tokens_mistral': 1363, 'n_tokens_neox': 1306, 'n_words': 284}