<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;

using Kirkin.Collections.Generic;
using Kirkin.Linq.Expressions;
using Kirkin.Reflection;
using Kirkin.Utilities;

namespace Kirkin
{
    /// <summary>
    /// Static <see cref="TypeMapping{T}.Default" /> proxy methods.
    /// Supports basic cloning and mapping operations. If you need to
    /// support advanced mapping scenarios (such as mapping via an interface
    /// or mapping to a derived type, use <see cref="TypeMapping{T}"/> instead.
    /// </summary>
    /// <remarks>
    /// The proxy methods are more restrictive than their counterparts defined on <see cref="TypeMapping{T}" />.
    /// The reason for having them in the first place is scenarios where we're mapping instances of the same type.
    /// In those cases it is often better to let type inference do its job than specify T manually, to prevent
    /// possible data loss if parameter type changes to a more derived type, but T is not updated at the same time.
    /// </remarks>
    public static class TypeMapping
    {
        /// <summary>
        /// TypeMapping{T}.Default.Clone proxy method.
        /// Creates a shallow clone of the given object.
        /// </summary>
        public static T Clone<T>(T original)
            where T : new()
        {
            return TypeMapping<T>.Default.Clone(original);
        }

        /// <summary>
        /// TypeMapping{T}.Default.Map proxy method.
        /// Reconciles the differences where necessary,
        /// and returns the target instance.
        /// </summary>
        public static T Map<T>(T source, T target)
        {
            return TypeMapping<T>.Default.Map(source, target);
        }
    }

    /// <summary>
    /// Reflection-based property mapper.
    /// </summary>
    public sealed class TypeMapping<T>
    {
        /// <summary>
        /// Default mapping instance for type T. Maps all properties
        /// which have an accessible getter for read (compare/hash)
        /// operations, and all properties which have accessible
        /// getters and setters for write (copy/clone) operations.
        /// </summary>
        public static TypeMapping<T> Default { get; }

        /// <summary>
        /// Type initialiser.
        /// </summary>
        static TypeMapping()
        {
            Default = new TypeMapping<T>(TypeUtil.Properties(typeof(T)));
        }

        private readonly IPropertyAccessor[] _propertyAccessors;

        /// <summary>
        /// Accessors for readable properties mapped by this instance.
        /// </summary>
        public Vector<IPropertyAccessor> PropertyAccessors<commit_msg>TypeMapping<T> trim<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;

using Kirkin.Collections.Generic;
using Kirkin.Linq.Expressions;
using Kirkin.Reflection;
using Kirkin.Utilities;

namespace Kirkin
{
    /// <summary>
    /// Static <see cref="TypeMapping{T}.Default" /> proxy methods.
    /// Supports basic cloning and mapping operations. If you need to
    /// support advanced mapping scenarios (such as mapping via an interface
    /// or mapping to a derived type, use <see cref="TypeMapping{T}"/> instead.
    /// </summary>
    /// <remarks>
    /// The proxy methods are more restrictive than their counterparts defined on <see cref="TypeMapping{T}" />.
    /// The reason for having them in the first place is scenarios where we're mapping instances of the same type.
    /// In those cases it is often better to let type inference do its job than specify T manually, to prevent
    /// possible data loss if parameter type changes to a more derived type, but T is not updated at the same time.
    /// </remarks>
    public static class TypeMapping
    {
        /// <summary>
        /// TypeMapping{T}.Default.Clone proxy method.
        /// Creates a shallow clone of the given object.
        /// </summary>
        public static T Clone<T>(T original)
            where T : new()
        {
            return TypeMapping<T>.Default.Clone(original);
        }

        /// <summary>
        /// TypeMapping{T}.Default.Map proxy method.
        /// Reconciles the differences where necessary,
        /// and returns the target instance.
        /// </summary>
        public static T Map<T>(T source, T target)
        {
            return TypeMapping<T>.Default.Map(source, target);
        }
    }

    /// <summary>
    /// Reflection-based property mapper.
    /// </summary>
    public sealed class TypeMapping<T>
    {
        /// <summary>
        /// Default mapping instance for type T. Maps all properties
        /// which have an accessible getter for read (compare/hash)
        /// operations, and all properties which have accessible
        /// getters and setters for write (copy/clone) operations.
        /// </summary>
        public static TypeMapping<T> Default { get; } = new TypeMapping<T>(TypeUtil.Properties(typeof(T)));

        private readonly IPropertyAccessor[] _propertyAccessors;

        /// <summary>
        /// Accessors for readable properties mapped by this instance.
        /// </summary>
        public Vector<IPropertyAccessor> PropertyAccessors
{'fraction_non_alphanumeric': 0.1082541457052357, 'fraction_numerical': 0.0, 'mean_word_length': 2.241545893719807, 'pattern_counts': {'":': 0, '<': 56, '<?xml version=': 0, '>': 56, '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': '1429828', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1337, 'n_words': 511}