<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Linq.Expressions;
using Signum.Utilities;
using System.Web.Mvc.Html;
using Signum.Entities;
using System.Reflection;
using Signum.Entities.Reflection;
using System.Configuration;

namespace Signum.Web
{
    public class EmbeddedControlSettings
    {
        public Dictionary<string, object> ViewData = new Dictionary<string, object>(0);
        public string ViewName { get; set; }
    }

    public static class EmbeddedControlHelper
    {
        public static void RenderEmbeddedControl<T, S>(this HtmlHelper helper, TypeContext<T> tc, Expression<Func<T, S>> property)
        {
            RenderEmbeddedControl<T, S>(helper, tc, property, null);
        }

        public static void RenderEmbeddedControl<T, S>(this HtmlHelper helper, TypeContext<T> tc, Expression<Func<T, S>> property, Action<EmbeddedControlSettings> settingsModifier)
        {
            EmbeddedControlSettings ec = new EmbeddedControlSettings();

            if (settingsModifier != null)
                settingsModifier(ec);

            TypeContext ntc = TypeContextUtilities.CleanTypeContext(Common.WalkExpression(tc, property));

            if(ec.ViewName == null)
                ec.ViewName = Navigator.Manager.EntitySettings[ntc.Type].OnPartialViewName((ModifiableEntity)ntc.UntypedValue); 
            
            ViewDataDictionary vdd = new ViewDataDictionary(ntc);
            if (ec.ViewData != null)
                vdd.AddRange(ec.ViewData); 

            helper.RenderPartial(ec.ViewName, vdd);
        }

        public static MvcHtmlString EmbeddedControl<T, S>(this HtmlHelper helper, TypeContext<T> tc, Expression<Func<T, S>> property)
        {
            return EmbeddedControl<T, S>(helper, tc, property, null);
        }

        public static MvcHtmlString EmbeddedControl<T, S>(this HtmlHelper helper, TypeContext<T> tc, Expression<Func<T, S>> property, Action<EmbeddedControlSettings> settingsModifier)
        {
            EmbeddedControlSettings ec = new EmbeddedControlSettings();

            if (settingsModifier != null)
                settingsModifier(ec);

            TypeContext ntc = TypeContextUtilities.CleanTypeContext(Common.WalkExpression(tc, property));

            if (ec.ViewName == null)
                ec.ViewName = Navigator.Manager.EntitySettings[ntc.Type].OnPartialViewName((ModifiableEntity)ntc.UntypedValue);

            ViewDataDictionary vdd = new ViewDataDictionary(ntc);
            if (ec.ViewData != null)
                vdd.AddRange(ec.ViewData);

            return helper.Partial(ec.ViewName, vdd);<commit_msg>EmbeddedControl - Remove unused RenderEmbeddedControl<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Linq.Expressions;
using Signum.Utilities;
using System.Web.Mvc.Html;
using Signum.Entities;
using System.Reflection;
using Signum.Entities.Reflection;
using System.Configuration;

namespace Signum.Web
{
    public class EmbeddedControl
    {
        public Dictionary<string, object> ViewData = new Dictionary<string, object>(0);
        public string ViewName { get; set; }
    }

    public static class EmbeddedControlHelper
    {
        public static MvcHtmlString EmbeddedControl<T, S>(this HtmlHelper helper, TypeContext<T> tc, Expression<Func<T, S>> property)
        {
            return EmbeddedControl<T, S>(helper, tc, property, null);
        }

        public static MvcHtmlString EmbeddedControl<T, S>(this HtmlHelper helper, TypeContext<T> tc, Expression<Func<T, S>> property, Action<EmbeddedControl> settingsModifier)
        {
            TypeContext context = TypeContextUtilities.CleanTypeContext(Common.WalkExpression(tc, property));

            var ec = new EmbeddedControl();
            
            if (settingsModifier != null)
                settingsModifier(ec);

            string viewName = ec.ViewName ?? 
                Navigator.Manager.EntitySettings[Reflector.ExtractLite(context.Type) ?? context.Type].OnPartialViewName((ModifiableEntity)context.UntypedValue);

            ViewDataDictionary vdd = new ViewDataDictionary(context);
            if (ec.ViewData != null)
                vdd.AddRange(ec.ViewData);

            return helper.Partial(viewName, vdd);
{'fraction_non_alphanumeric': 0.09432672590567327, 'fraction_numerical': 0.000455684666210982, 'mean_word_length': 3.076137418755803, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, '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': '4324584', 'n_tokens_mistral': 1207, 'n_tokens_neox': 1203, 'n_words': 269}