<commit_before>﻿using System;
using System.Windows;

namespace Solutionizer.Infrastructure {
    public static class ModelAttacher {
        public static readonly DependencyProperty AttachModelProperty =
            DependencyProperty.RegisterAttached("AttachModel", typeof (Type), typeof (ModelAttacher),
                                                new PropertyMetadata(null, AttachModelCallback));

        private static void AttachModelCallback(DependencyObject source, DependencyPropertyChangedEventArgs args) {
            var modelType = args.NewValue as Type;
            var view = source as FrameworkElement;
            if (modelType == null || view == null) {
                return;
            }

            try {
                var model = Activator.CreateInstance(modelType);
                view.DataContext = model;
            } catch (Exception ex) {
                throw new InvalidOperationException(string.Format("Cannot create instance of model type: {0}", modelType), ex);
            }
        }

        public static string GetAttachModel(UIElement element) {
            return (string) element.GetValue(AttachModelProperty);
        }

        public static void SetAttachModel(UIElement element, string value) {
            element.SetValue(AttachModelProperty, value);
        }
    }
}<commit_msg>fixed parameter from string to type (it worked before, but VS designer complained)<commit_after>﻿using System;
using System.Windows;

namespace Solutionizer.Infrastructure {
    public static class ModelAttacher {
        public static readonly DependencyProperty AttachModelProperty =
            DependencyProperty.RegisterAttached("AttachModel", typeof (Type), typeof (ModelAttacher),
                                                new PropertyMetadata(null, AttachModelCallback));

        private static void AttachModelCallback(DependencyObject source, DependencyPropertyChangedEventArgs args) {
            var modelType = args.NewValue as Type;
            var view = source as FrameworkElement;
            if (modelType == null || view == null) {
                return;
            }

            try {
                var model = Activator.CreateInstance(modelType);
                view.DataContext = model;
            } catch (Exception ex) {
                throw new InvalidOperationException(string.Format("Cannot create instance of model type: {0}", modelType), ex);
            }
        }

        public static Type GetAttachModel(UIElement element) {
            return (Type)element.GetValue(AttachModelProperty);
        }

        public static void SetAttachModel(UIElement element, Type value) {
            element.SetValue(AttachModelProperty, value);
        }
    }
}
{'fraction_non_alphanumeric': 0.07195032870708547, 'fraction_numerical': 0.0007304601899196494, 'mean_word_length': 2.245260663507109, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5440866', 'n_tokens_mistral': 629, 'n_tokens_neox': 599, 'n_words': 177}