<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Script.Serialization;
using Signum.Entities;
using Signum.Engine;
using Signum.Utilities;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Signum.Web.Controllers
{
    public class LiteJavaScriptConverter : JsonConverter
    {
        public override bool CanConvert(Type objectType)
        {
            return typeof(Lite<IdentifiableEntity>).IsAssignableFrom(objectType);
        }

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            JObject jsonObject = JObject.Load(reader);

            string liteKey = (string)jsonObject["Key"];
            return Lite.Parse(liteKey);
        }

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            Lite<IdentifiableEntity> lite = (Lite<IdentifiableEntity>)value;

            writer.WritePropertyName("Key");
            serializer.Serialize(writer, lite.Key());
            writer.WritePropertyName("Id");
            serializer.Serialize(writer, lite.Id);
            writer.WritePropertyName("ToStr");
            serializer.Serialize(writer, lite.ToString());
        }
    }

    public class EnumJavaScriptConverter : JsonConverter
    {
        public override bool CanConvert(Type objectType)
        {
            return objectType == typeof(Enum);
        }

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            throw new NotImplementedException();
        }

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            Enum myEnum = (Enum)value;

            writer.WritePropertyName("Id");
            serializer.Serialize(writer, Convert.ToInt32(myEnum));
            writer.WritePropertyName("Value");
            serializer.Serialize(writer, myEnum.ToString());
            writer.WritePropertyName("ToStr");
            serializer.Serialize(writer, myEnum.NiceToString());
        }
    }
}<commit_msg>fix JsonConverter<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Script.Serialization;
using Signum.Entities;
using Signum.Engine;
using Signum.Utilities;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Signum.Web.Controllers
{
    public class LiteJavaScriptConverter : JsonConverter
    {
        public override bool CanConvert(Type objectType)
        {
            return typeof(Lite<IdentifiableEntity>).IsAssignableFrom(objectType);
        }

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            JObject jsonObject = JObject.Load(reader);

            string liteKey = (string)jsonObject["Key"];
            return Lite.Parse(liteKey);
        }

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            Lite<IdentifiableEntity> lite = (Lite<IdentifiableEntity>)value;
            writer.WriteStartObject();

            writer.WritePropertyName("Key");
            serializer.Serialize(writer, lite.Key());
            writer.WritePropertyName("Id");
            serializer.Serialize(writer, lite.Id);
            writer.WritePropertyName("ToStr");
            serializer.Serialize(writer, lite.ToString());

            writer.WriteEndObject();
        }
    }

    public class EnumJavaScriptConverter : JsonConverter
    {
        public override bool CanConvert(Type objectType)
        {
            return objectType == typeof(Enum);
        }

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            throw new NotImplementedException();
        }

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            Enum myEnum = (Enum)value;

            writer.WritePropertyName("Id");
            serializer.Serialize(writer, Convert.ToInt32(myEnum));
            writer.WritePropertyName("Value");
            serializer.Serialize(writer, myEnum.ToString());
            writer.WritePropertyName("ToStr");
            serializer.Serialize(writer, myEnum.NiceToString());
        }
    }
}
{'fraction_non_alphanumeric': 0.09012969883490878, 'fraction_numerical': 0.0008793141349747197, 'mean_word_length': 2.6901865369018654, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '4145036', 'n_tokens_mistral': 1138, 'n_tokens_neox': 1137, 'n_words': 247}