<commit_before>﻿#if WINDOWS
using System;
using System.Xml;
using System.Reflection;
using System.ComponentModel;
using System.Collections.Generic;
using System.Globalization;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;

namespace Delta.Tiled
{
    internal static class TmxImporterExtensions
    {
        internal static void ImportLayer(this ILayer layer, XmlNode node)
        {
            layer.ID = node.Attributes["name"].Value;
            layer.IsVisible = (node.Attributes["visible"] != null) ? int.Parse(node.Attributes["visible"].Value, CultureInfo.InvariantCulture) == 1 : true;
        }

        internal static void ImportXmlProperties(this object obj, XmlNode node)
        {
            if (node == null)
                return;
            bool isFound = false;
            foreach (XmlNode propertyNode in node.ChildNodes)
            {
                isFound = false;
                string name = propertyNode.Attributes["name"] == null ? null : propertyNode.Attributes["name"].Value;
                string value = propertyNode.Attributes["value"].Value;
                if (!string.IsNullOrEmpty(name))
                {
                    PropertyInfo[] properties = obj.GetType().GetProperties();
                    foreach (var propertyInfo in properties)
                    {
                        var attributes = propertyInfo.GetCustomAttributes(true);
                        foreach (var attribute in attributes)
                        {
                            ContentSerializerAttribute contentSerializerAttribute = attribute as ContentSerializerAttribute;
                            if (contentSerializerAttribute != null)
                            {
                                if (contentSerializerAttribute.ElementName != null)
                                {
                                    if (contentSerializerAttribute.ElementName.ToLower() == name.ToLower())
                                    {
                                        isFound = true;
                                        BindProperty(obj, propertyInfo, value);
                                        break;
                                    }
                                }
                            }
                        }
                        if (!isFound && name.ToLower() == propertyInfo.Name.ToLower())
                        {
                            isFound = true;
                            BindProperty(obj, propertyInfo, value);
                        }
                    }
                    MethodInfo[] methods = obj.GetType().GetMethods();
                    foreach (var methodInfo in methods)
                    {
                        if (!isFound && name.ToLower() == methodInfo.Name.ToLower())
                        {
                            isFound = true;
                            InvokeMethod(obj, methodInfo, value);
                        }
                    }
                }
                else
                    continue;
                if (!isFound)
                {
                    switch (name.ToLower())
                    {
                        case "offset":
                            TransformableEntity entity = obj as TransformableEntity;
                            if (entity != null)
                            {
                                string[] split = value.Split(new string[] { ",", ":", ".", "/", ";", "'", "-"},  StringSplitOptions.RemoveEmptyEntries);
                                entity.Position += new Vector2(float.Parse(split[0], CultureInfo.InvariantCulture), float.Parse(split[1], CultureInfo.InvariantCulture));
                            }
                            break;
                    }
                    throw new Exception(String.Format("Could not find a property or method with the name '{0}' to bind or call in the type '{1}'.", name, obj.GetType().Name));
                }
            }
        }

        static void BindProperty(object bindObject, PropertyInfo property, string rawValue)
        {
            property.SetValue(bindObject, ChangeType(rawValue, property.PropertyType), null);
        }

        static object ChangeType(object value, Type conversionType)
        {<commit_msg>Fixed offset bug.<commit_after>﻿#if WINDOWS
using System;
using System.Xml;
using System.Reflection;
using System.ComponentModel;
using System.Collections.Generic;
using System.Globalization;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;

namespace Delta.Tiled
{
    internal static class TmxImporterExtensions
    {
        internal static void ImportLayer(this ILayer layer, XmlNode node)
        {
            layer.ID = node.Attributes["name"].Value;
            layer.IsVisible = (node.Attributes["visible"] != null) ? int.Parse(node.Attributes["visible"].Value, CultureInfo.InvariantCulture) == 1 : true;
        }

        internal static void ImportXmlProperties(this object obj, XmlNode node)
        {
            if (node == null)
                return;
            bool isFound = false;
            foreach (XmlNode propertyNode in node.ChildNodes)
            {
                isFound = false;
                string name = propertyNode.Attributes["name"] == null ? null : propertyNode.Attributes["name"].Value;
                string value = propertyNode.Attributes["value"].Value;
                if (!string.IsNullOrEmpty(name))
                {
                    PropertyInfo[] properties = obj.GetType().GetProperties();
                    foreach (var propertyInfo in properties)
                    {
                        var attributes = propertyInfo.GetCustomAttributes(true);
                        foreach (var attribute in attributes)
                        {
                            ContentSerializerAttribute contentSerializerAttribute = attribute as ContentSerializerAttribute;
                            if (contentSerializerAttribute != null)
                            {
                                if (contentSerializerAttribute.ElementName != null)
                                {
                                    if (contentSerializerAttribute.ElementName.ToLower() == name.ToLower())
                                    {
                                        isFound = true;
                                        BindProperty(obj, propertyInfo, value);
                                        break;
                                    }
                                }
                            }
                        }
                        if (!isFound && name.ToLower() == propertyInfo.Name.ToLower())
                        {
                            isFound = true;
                            BindProperty(obj, propertyInfo, value);
                        }
                        if (!isFound)
                        {
                            switch (name.ToLower())
                            {
                                case "offset":
                                    TransformableEntity entity = obj as TransformableEntity;
                                    if (entity != null)
                                    {
                                        string[] split = value.Split(new string[] { ",", ":", ".", "/", ";", "'", "-" }, StringSplitOptions.RemoveEmptyEntries);
                                        entity.Position += new Vector2(float.Parse(split[0], CultureInfo.InvariantCulture), float.Parse(split[1], CultureInfo.InvariantCulture));
                                        isFound = true;
                                    }
                                    break;
                            }
                        }
                    }
                    MethodInfo[] methods = obj.GetType().GetMethods();
                    foreach (var methodInfo in methods)
                    {
                        if (!isFound && name.ToLower() == methodInfo.Name.ToLower())
                        {
                            isFound = true;
                            InvokeMethod(obj, methodInfo, value);
                        }
                    }
                }
                else
                    continue;
                if (!isFound)
                    throw new Exception(String.Format("Could not find a property or method with the name '{0}' to bind or call in the type '{1}'.", name, obj.GetType().Name));
            }
        }

        static void BindProperty(object bindObject, PropertyInfo property, string rawValue)
        {
            property.SetValue(bindObject, ChangeType(rawValue, property.PropertyType), null);
        }

        static object ChangeType(object value, Type conversionType)
        {
{'fraction_non_alphanumeric': 0.08424159854677565, 'fraction_numerical': 0.0013623978201634877, 'mean_word_length': 1.1211172646279797, 'pattern_counts': {'":': 4, '<': 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': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '238857', 'n_tokens_mistral': 1843, 'n_tokens_neox': 1737, 'n_words': 416}