<commit_before>﻿using Sakuno.UserInterface.ObjectOperations;
using System;
using System.Windows.Data;
using System.Windows.Markup;

namespace Sakuno.UserInterface.Commands
{
    public class InvokeMethodExtension : MarkupExtension
    {
        string r_Method;

        object r_Parameter;

        public InvokeMethodExtension(string rpMethod) : this(rpMethod, null) { }
        public InvokeMethodExtension(string rpMethod, object rpParameter)
        {
            r_Method = rpMethod;
            r_Parameter = rpParameter;
        }

        public override object ProvideValue(IServiceProvider rpServiceProvider)
        {
            var rInvokeMethod = new InvokeMethod() { Method = r_Method };

            if (r_Parameter != null)
            {
                var rParameter = new MethodParameter();

                var rBinding = r_Parameter as Binding;
                if (rBinding == null)
                    rParameter.Value = r_Parameter;
                else
                    BindingOperations.SetBinding(rParameter, MethodParameter.ValueProperty, rBinding);

                rInvokeMethod.Parameters.Add(rParameter);
            }

            return new ObjectOperationCommand() { Operations = { rInvokeMethod } };
        }
    }
}<commit_msg>Add target property for InvokeMethod markup extension<commit_after>﻿using Sakuno.UserInterface.ObjectOperations;
using System;
using System.Windows.Data;
using System.Windows.Markup;

namespace Sakuno.UserInterface.Commands
{
    public class InvokeMethodExtension : MarkupExtension
    {
        string r_Method;

        object r_Parameter;

        public object Target { get; set; }

        public InvokeMethodExtension(string rpMethod) : this(rpMethod, null) { }
        public InvokeMethodExtension(string rpMethod, object rpParameter)
        {
            r_Method = rpMethod;
            r_Parameter = rpParameter;
        }

        public override object ProvideValue(IServiceProvider rpServiceProvider)
        {
            var rInvokeMethod = new InvokeMethod() { Method = r_Method };

            if (r_Parameter != null)
            {
                var rParameter = new MethodParameter();

                var rBinding = r_Parameter as Binding;
                if (rBinding == null)
                    rParameter.Value = r_Parameter;
                else
                    BindingOperations.SetBinding(rParameter, MethodParameter.ValueProperty, rBinding);

                rInvokeMethod.Parameters.Add(rParameter);
            }

            if (Target != null)
            {
                var rBinding = Target as Binding;
                if (rBinding != null)
                    BindingOperations.SetBinding(rInvokeMethod, InvokeMethod.TargetProperty, rBinding);
                else
                    rInvokeMethod.Target = Target;
            }

            return new ObjectOperationCommand() { Operations = { rInvokeMethod } };
        }
    }
}
{'fraction_non_alphanumeric': 0.06990159484221242, 'fraction_numerical': 0.0, 'mean_word_length': 1.9777777777777779, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3517483', 'n_tokens_mistral': 742, 'n_tokens_neox': 705, 'n_words': 168}