<commit_before>﻿using System;
using System.Collections.Generic;
using CleaveFramework.Scene;

namespace CleaveFramework.Factory
{
    /// <summary>
    /// defines a post instantiation constructor for the object
    /// </summary>
    /// <param name="obj">object to construct</param>
    /// <returns>constructed object</returns>
    public delegate object Constructor(object obj);

    /// <summary>
    /// generic Factory implementation
    /// </summary>
    static class Factory
    {
        static Dictionary<Type, Constructor> _constructors = new Dictionary<Type, Constructor>();

        /// <summary>
        /// Sets a post instantiation constructor to an object type
        /// </summary>
        /// <typeparam name="T">object type</typeparam>
        /// <param name="constructor">delegate to act as constructor</param>
        static public void SetConstructor<T>(Constructor constructor)
        {
            // for now we are a single delegate
            if (_constructors.ContainsKey(typeof (T))) return;
            _constructors.Add(typeof(T), constructor);
        }

        /// <summary>
        /// Create object of type T, if a constructor exists in the Factory use it on the object
        /// before returning it
        /// </summary>
        /// <typeparam name="T">Type of object to construct</typeparam>
        /// <returns>constructed object</returns>
        static public object Create<T>()
        {
            var obj = Activator.CreateInstance<T>();

            if(_constructors.ContainsKey(typeof(T)))
            {
                obj = (T)_constructors[typeof (T)].Invoke(obj);
            }
            return obj;
        }

        /// <summary>
        /// Create an object of type T and run this custom constructor on it
        /// </summary>
        /// <typeparam name="T">Type of object to create</typeparam>
        /// <param name="constructor">constructor to run on object</param>
        /// <returns>constructed object</returns>
        static public object Create<T>(Constructor constructor)
        {
            var obj = Activator.CreateInstance<T>();

            if (constructor != null)
            {<commit_msg>allow constructors to be set to null<commit_after>﻿using System;
using System.Collections.Generic;
using CleaveFramework.Scene;

namespace CleaveFramework.Factory
{
    /// <summary>
    /// defines a post instantiation constructor for the object
    /// </summary>
    /// <param name="obj">object to construct</param>
    /// <returns>constructed object</returns>
    public delegate object Constructor(object obj);

    /// <summary>
    /// generic Factory implementation
    /// </summary>
    static class Factory
    {
        static Dictionary<Type, Constructor> _constructors = new Dictionary<Type, Constructor>();

        /// <summary>
        /// Sets a post instantiation constructor to an object type
        /// </summary>
        /// <typeparam name="T">object type</typeparam>
        /// <param name="constructor">delegate to act as constructor</param>
        static public void SetConstructor<T>(Constructor constructor)
        {
            // for now we are a single delegate
            if (_constructors.ContainsKey(typeof (T))) return;
            _constructors.Add(typeof(T), constructor);
        }

        /// <summary>
        /// Create object of type T, if a constructor exists in the Factory use it on the object
        /// before returning it
        /// </summary>
        /// <typeparam name="T">Type of object to construct</typeparam>
        /// <returns>constructed object</returns>
        static public object Create<T>()
        {
            var obj = Activator.CreateInstance<T>();

            if(_constructors.ContainsKey(typeof(T)))
            {
                if(_constructors[typeof(T)] != null)
                    obj = (T)_constructors[typeof (T)].Invoke(obj);
            }
            return obj;
        }

        /// <summary>
        /// Create an object of type T and run this custom constructor on it
        /// </summary>
        /// <typeparam name="T">Type of object to create</typeparam>
        /// <param name="constructor">constructor to run on object</param>
        /// <returns>constructed object</returns>
        static public object Create<T>(Constructor constructor)
        {
            var obj = Activator.CreateInstance<T>();

            if (constructor != null)
            {
{'fraction_non_alphanumeric': 0.12072072072072072, 'fraction_numerical': 0.0, 'mean_word_length': 2.0501373626373627, 'pattern_counts': {'":': 0, '<': 73, '<?xml version=': 0, '>': 73, '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': '7545336', 'n_tokens_mistral': 1081, 'n_tokens_neox': 1063, 'n_words': 338}