<commit_before>﻿using System;
using System.Reflection;
using DotVVM.Framework.Controls.DynamicData.Metadata;

namespace DotVVM.Framework.Controls.DynamicData.PropertyHandlers.FormEditors
{
    /// <summary>
    /// Renders a CheckBox control for properties of boolean type.
    /// </summary>
    public class CheckBoxEditorProvider : FormEditorProviderBase
    {
        public override bool CanHandleProperty(PropertyInfo propertyInfo, DynamicDataContext context)
        {
            return UnwrapNullableType(propertyInfo.PropertyType) == typeof(bool);
        }
        
        public override bool CanValidate => true;

        public override bool RenderDefaultLabel => false;

        public override void CreateControl(DotvvmControl container, PropertyDisplayMetadata property, DynamicDataContext context)
        {
            var checkBox = new CheckBox();
            container.Children.Add(checkBox);

            var cssClass = ControlHelpers.ConcatCssClasses(ControlCssClass, property.Styles?.FormControlCssClass);
            if (!string.IsNullOrEmpty(cssClass))
            {
                checkBox.Attributes["class"] = cssClass;
            }

            checkBox.Text = property.DisplayName;
            checkBox.SetBinding(CheckableControlBase.CheckedValueProperty, context.CreateValueBinding(property.PropertyInfo.Name));

            if (checkBox.IsPropertySet(DynamicEntity.EnabledProperty))
            {
                ControlHelpers.CopyProperty(checkBox, DynamicEntity.EnabledProperty, checkBox, CheckableControlBase.EnabledProperty);
            }
        }
    }
}<commit_msg>CheckBox issue fixed<commit_after>﻿using System;
using System.Reflection;
using DotVVM.Framework.Controls.DynamicData.Metadata;

namespace DotVVM.Framework.Controls.DynamicData.PropertyHandlers.FormEditors
{
    /// <summary>
    /// Renders a CheckBox control for properties of boolean type.
    /// </summary>
    public class CheckBoxEditorProvider : FormEditorProviderBase
    {
        public override bool CanHandleProperty(PropertyInfo propertyInfo, DynamicDataContext context)
        {
            return UnwrapNullableType(propertyInfo.PropertyType) == typeof(bool);
        }
        
        public override bool CanValidate => true;

        public override bool RenderDefaultLabel => false;

        public override void CreateControl(DotvvmControl container, PropertyDisplayMetadata property, DynamicDataContext context)
        {
            var checkBox = new CheckBox();
            container.Children.Add(checkBox);

            var cssClass = ControlHelpers.ConcatCssClasses(ControlCssClass, property.Styles?.FormControlCssClass);
            if (!string.IsNullOrEmpty(cssClass))
            {
                checkBox.Attributes["class"] = cssClass;
            }

            checkBox.Text = property.DisplayName;
            checkBox.SetBinding(CheckBox.CheckedProperty, context.CreateValueBinding(property.PropertyInfo.Name));

            if (checkBox.IsPropertySet(DynamicEntity.EnabledProperty))
            {
                ControlHelpers.CopyProperty(checkBox, DynamicEntity.EnabledProperty, checkBox, CheckableControlBase.EnabledProperty);
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.07902924704418171, 'fraction_numerical': 0.0, 'mean_word_length': 2.8410991636798086, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2376115', 'n_tokens_mistral': 779, 'n_tokens_neox': 765, 'n_words': 152}