<commit_before>// <copyright file="LateBoundProjection.cs" company="million miles per hour ltd">
// Copyright (c) 2013-2014 All Right Reserved
// 
// This source is subject to the MIT License.
// Please see the License.txt file for more information.
// All other rights reserved.
// 
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
// </copyright>

using System;

namespace KodeKandy.Mapnificent.Projections
{
    /// <summary>
    ///     A late bound projection that is resolved against the mapper when it is needed.
    /// </summary>
    public class LateBoundProjection : Projection
    {
        public LateBoundProjection(ProjectionType projectionType, Mapper mapper) : base(projectionType, mapper)
        {
        }

        public override object Apply(object from, object to = null, bool mapInto = false)
        {
            try
            {
                // TODO: cache this value.
                var map = Mapper.GetProjection(ProjectionType);

                return map.Apply(from, to, mapInto);
            }
            catch (Exception ex)
            {
                var msg = string.Format("Error applying LateBoundProjection of type {0}", ProjectionType);
                throw new MapnificentException(msg, ex, Mapper);
            }<commit_msg>Added Lazy init of LateBoundProjection.<commit_after>// <copyright file="LateBoundProjection.cs" company="million miles per hour ltd">
// Copyright (c) 2013-2014 All Right Reserved
// 
// This source is subject to the MIT License.
// Please see the License.txt file for more information.
// All other rights reserved.
// 
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
// </copyright>

using System;

namespace KodeKandy.Mapnificent.Projections
{
    /// <summary>
    ///     A late bound projection that is resolved against the mapper when it is needed.
    /// </summary>
    public class LateBoundProjection : Projection
    {
        public LateBoundProjection(ProjectionType projectionType, Mapper mapper) : base(projectionType, mapper)
        {
            projection = new Lazy<IProjection>(() => Mapper.GetProjection(ProjectionType));
        }

        private readonly Lazy<IProjection> projection;

        public override object Apply(object from, object to = null, bool mapInto = false)
        {
            try
            {
                return projection.Value.Apply(from, to, mapInto);
            }
            catch (Exception ex)
            {
                var msg = string.Format("Error applying LateBoundProjection of type {0}", ProjectionType);
                throw new MapnificentException(msg, ex, Mapper);
            }
{'fraction_non_alphanumeric': 0.08641975308641975, 'fraction_numerical': 0.006006006006006006, 'mean_word_length': 2.4106939704209327, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 14, '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': '250821', 'n_tokens_mistral': 792, 'n_tokens_neox': 753, 'n_words': 283}