<commit_before>using System;
using System.Collections.Generic;
using System.Linq;
using DotVVM.Framework.Runtime;
using Newtonsoft.Json;
using DotVVM.Framework.Binding;
using DotVVM.Framework.Hosting;
using DotVVM.Framework.Binding.Expressions;

namespace DotVVM.Framework.Controls
{
    /// <summary>
    /// A base class for all controls with Dothtml markup.
    /// </summary>
    public class DotvvmMarkupControl : HtmlGenericControl
    {

        /// <summary>
        /// Initializes a new instance of the <see cref="DotvvmMarkupControl"/> class.
        /// </summary>
        public DotvvmMarkupControl() : base("div")
        {
            SetValue(Internal.IsNamingContainerProperty, true);
            SetValue(Internal.IsControlBindingTargetProperty, true);
        }

        protected internal override void OnLoad(Hosting.IDotvvmRequestContext context)
        {
            EnsureControlHasId();
            base.OnLoad(context);
        }

        protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context)
        {
            var properties =
                GetDeclaredProperties()
                .Where(p => !p.PropertyType.IsAssignableFrom(typeof(DotvvmMarkupControl)))
                .Select(GetPropertySerializationInfo)
                .Where(p => p.IsSerializable)
                .Select(p => JsonConvert.SerializeObject(p.Property.Name) + ": " + p.Js);

            writer.WriteKnockoutDataBindComment("withControlProperties", "{ " + string.Join(", ", properties) + " }");
            base.RenderContents(writer, context);
            writer.WriteKnockoutDataBindEndComment();
        }

        private PropertySerializeInfo GetPropertySerializationInfo(DotvvmProperty property)
        {
            var binding = GetBinding(property);

            if (binding == null)
            {

                return new PropertySerializeInfo
                {
                    Property = property,
                    Js = JsonConvert.SerializeObject(GetValue(property), Formatting.None),
                    IsSerializable = true
                };
            }
            else if (binding is IValueBinding)
            {
                return new PropertySerializeInfo
                {<commit_msg>fixed bug in DotvvmMarkupControl rendering properties<commit_after>using System;
using System.Collections.Generic;
using System.Linq;
using DotVVM.Framework.Runtime;
using Newtonsoft.Json;
using DotVVM.Framework.Binding;
using DotVVM.Framework.Hosting;
using DotVVM.Framework.Binding.Expressions;

namespace DotVVM.Framework.Controls
{
    /// <summary>
    /// A base class for all controls with Dothtml markup.
    /// </summary>
    public class DotvvmMarkupControl : HtmlGenericControl
    {

        /// <summary>
        /// Initializes a new instance of the <see cref="DotvvmMarkupControl"/> class.
        /// </summary>
        public DotvvmMarkupControl() : base("div")
        {
            SetValue(Internal.IsNamingContainerProperty, true);
            SetValue(Internal.IsControlBindingTargetProperty, true);
        }

        protected internal override void OnLoad(Hosting.IDotvvmRequestContext context)
        {
            EnsureControlHasId();
            base.OnLoad(context);
        }

        protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context)
        {
            var properties =
                GetDeclaredProperties()
                .Where(p => !p.DeclaringType.IsAssignableFrom(typeof(DotvvmMarkupControl)))
                .Select(GetPropertySerializationInfo)
                .Where(p => p.IsSerializable)
                .Select(p => JsonConvert.SerializeObject(p.Property.Name) + ": " + p.Js);

            writer.WriteKnockoutDataBindComment("withControlProperties", "{ " + string.Join(", ", properties) + " }");
            base.RenderContents(writer, context);
            writer.WriteKnockoutDataBindEndComment();
        }

        private PropertySerializeInfo GetPropertySerializationInfo(DotvvmProperty property)
        {
            var binding = GetBinding(property);

            if (binding == null)
            {

                return new PropertySerializeInfo
                {
                    Property = property,
                    Js = JsonConvert.SerializeObject(GetValue(property), Formatting.None),
                    IsSerializable = true
                };
            }
            else if (binding is IValueBinding)
            {
                return new PropertySerializeInfo
                {
{'fraction_non_alphanumeric': 0.08977446901686008, 'fraction_numerical': 0.0, 'mean_word_length': 2.0740242261103634, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 19, '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': '1883963', 'n_tokens_mistral': 1165, 'n_tokens_neox': 1123, 'n_words': 227}