<commit_before>﻿// <copyright file="ObjectExtensions.cs" company="ConfigR contributors">
//  Copyright (c) ConfigR contributors. (<EMAIL>)
// </copyright>

namespace ConfigR
{
    using System;
    using System.Diagnostics.CodeAnalysis;
    using System.Globalization;
    using Common.Logging;
    using Newtonsoft.Json;

    internal static class ObjectExtensions
    {
        private static readonly ILog log = LogManager.GetCurrentClassLogger();
        private static readonly JsonSerializerSettings jsonSettings = new JsonSerializerSettings
        {
            PreserveReferencesHandling = PreserveReferencesHandling.Objects,
            ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
            MaxDepth = 4
        };

        [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Safe in this case.")]
        public static string TryToJsv(this object value)
        {
            try
            {
                return JsonConvert.SerializeObject(value, Formatting.Indented, jsonSettings);
            }
            catch (Exception ex)
            {
                log.TraceFormat(CultureInfo.InvariantCulture, "Error converting '{0}' to JSV.", ex, value);
                return JsonConvert.SerializeObject(value.GetType(), Formatting.Indented, jsonSettings);
            }
        }

        public static T CastForRetreival<T>(this object value, string key)
        {
            try
            {
                return (T)value;
            }<commit_msg>#137 changed config value logging to be single line<commit_after>﻿// <copyright file="ObjectExtensions.cs" company="ConfigR contributors">
//  Copyright (c) ConfigR contributors. (<EMAIL>)
// </copyright>

namespace ConfigR
{
    using System;
    using System.Diagnostics.CodeAnalysis;
    using System.Globalization;
    using Common.Logging;
    using Newtonsoft.Json;

    internal static class ObjectExtensions
    {
        private static readonly ILog log = LogManager.GetCurrentClassLogger();
        private static readonly JsonSerializerSettings jsonSettings = new JsonSerializerSettings
        {
            PreserveReferencesHandling = PreserveReferencesHandling.Objects,
            ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
            MaxDepth = 4
        };

        [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Safe in this case.")]
        public static string TryToJsv(this object value)
        {
            try
            {
                return JsonConvert.SerializeObject(value, Formatting.None, jsonSettings);
            }
            catch (Exception ex)
            {
                log.TraceFormat(CultureInfo.InvariantCulture, "Error converting '{0}' to JSV.", ex, value);
                return JsonConvert.SerializeObject(value.GetType(), Formatting.None, jsonSettings);
            }
        }

        public static T CastForRetreival<T>(this object value, string key)
        {
            try
            {
                return (T)value;
            }
{'fraction_non_alphanumeric': 0.0819300518134715, 'fraction_numerical': 0.0048575129533678756, 'mean_word_length': 2.3394594594594595, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '1859504', 'n_tokens_mistral': 760, 'n_tokens_neox': 738, 'n_words': 188}