<commit_before>﻿using System.Reflection;
using Kinugasa.Map.Attributes;

/// <summary>
/// Provide featuer of mapping some values.
/// </summary>
namespace Kinugasa.Map
{
    /// <summary>
    /// To map same properties value between classA and classB.
    /// </summary>
    public static class PropertyMapper
    {
        /// <summary>
        /// To map same properties value between classA and classB.
        /// ClassB properties value will map to classA properties.
        /// </summary>
        /// <typeparam name="TDestination">Instance of classA.</typeparam>
        /// <typeparam name="TSource">Instance of classB.</typeparam>
        public static void Map<TDestination, TSource>(ref TDestination destination, TSource source)
            where TDestination : class
            where TSource : class
        {
            var typeInfo = destination.GetType().GetTypeInfo();
            var typeInfo2 = source.GetType().GetTypeInfo();

            foreach (PropertyInfo propertyInfo in typeInfo.DeclaredProperties)
            {
                foreach (PropertyInfo propertyInfo2 in typeInfo2.DeclaredProperties)
                {
                    if (propertyInfo.Name == propertyInfo2.Name)
                    {
                        propertyInfo.SetValue(destination, propertyInfo2.GetValue(source));
                        break;
                    }
                }
            }
        }

        /// <summary>
        /// To map properties value between classA and classB, using by <see cref="MapAttribute"/>.
        /// ClassB properties value will map to classA properties, if classA's property use <see cref="MapAttribute"/>.
        /// ClassA have to specify classB's property name using by <see cref="MapAttribute"/>.
        /// </summary>
        /// <typeparam name="TDestination">Instance of classA.</typeparam>
        /// <typeparam name="TSource">Instance of classB.</typeparam>
        public static void AttributeMap<TDestination, TSource>(ref TDestination destination, TSource source)
            where TDestination : class
            where TSource : class
        {
            var typeInfo = destination.GetType().GetTypeInfo();
            var typeInfo2 = source.GetType().GetTypeInfo();

            foreach (PropertyInfo propertyInfo in typeInfo.DeclaredProperties)
            {
                var attribute = propertyInfo.GetCustomAttribute(typeof(MapAttribute));
                if (attribute == null)
                {
                    continue;
                }

                string attributeName = ((MapAttribute)attribute).AttributeName;
                foreach (PropertyInfo propertyInfo2 in typeInfo2.DeclaredProperties)
                {
                    if (attributeName == propertyInfo2.Name)
                    {
                        propertyInfo.SetValue(destination, propertyInfo2.GetValue(source));
                    }
                }
            }
        }
    }
}<commit_msg>Refactoring some variable's name<commit_after>﻿using System.Reflection;
using Kinugasa.Map.Attributes;

/// <summary>
/// Provide featuer of mapping some values.
/// </summary>
namespace Kinugasa.Map
{
    /// <summary>
    /// To map same properties value between classA and classB.
    /// </summary>
    public static class PropertyMapper
    {
        /// <summary>
        /// To map same properties value between classA and classB.
        /// ClassB properties value will map to classA properties.
        /// </summary>
        /// <typeparam name="TDestination">Instance of classA.</typeparam>
        /// <typeparam name="TSource">Instance of classB.</typeparam>
        public static void Map<TDestination, TSource>(ref TDestination destination, TSource source)
            where TDestination : class
            where TSource : class
        {
            var destinationTypeInfo = destination.GetType().GetTypeInfo();
            var sourceTypeInfo = source.GetType().GetTypeInfo();

            foreach (PropertyInfo destinationPropertyInfo in destinationTypeInfo.DeclaredProperties)
            {
                foreach (PropertyInfo sourcePropertyInfo in sourceTypeInfo.DeclaredProperties)
                {
                    if (destinationPropertyInfo.Name == sourcePropertyInfo.Name)
                    {
                        destinationPropertyInfo.SetValue(destination, sourcePropertyInfo.GetValue(source));
                        break;
                    }
                }
            }
        }

        /// <summary>
        /// To map properties value between classA and classB, using by <see cref="MapAttribute"/>.
        /// ClassB properties value will map to classA properties, if classA's property use <see cref="MapAttribute"/>.
        /// ClassA have to specify classB's property name using by <see cref="MapAttribute"/>.
        /// </summary>
        /// <typeparam name="TDestination">Instance of classA.</typeparam>
        /// <typeparam name="TSource">Instance of classB.</typeparam>
        public static void AttributeMap<TDestination, TSource>(ref TDestination destination, TSource source)
            where TDestination : class
            where TSource : class
        {
            var destinationTypeInfo = destination.GetType().GetTypeInfo();
            var sourceTypeInfo = source.GetType().GetTypeInfo();

            foreach (PropertyInfo destinationPropertyInfo in destinationTypeInfo.DeclaredProperties)
            {
                var attribute = destinationPropertyInfo.GetCustomAttribute(typeof(MapAttribute));
                if (attribute == null)
                {
                    continue;
                }

                string attributeName = ((MapAttribute)attribute).AttributeName;
                foreach (PropertyInfo sourcePropertyInfo in sourceTypeInfo.DeclaredProperties)
                {
                    if (attributeName == sourcePropertyInfo.Name)
                    {
                        destinationPropertyInfo.SetValue(destination, sourcePropertyInfo.GetValue(source));
                    }
                }
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.09200849812060795, 'fraction_numerical': 0.0016342539630658604, 'mean_word_length': 1.8280961182994455, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, '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': '3743548', 'n_tokens_mistral': 1400, 'n_tokens_neox': 1375, 'n_words': 375}