<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Xml.Serialization;
using System.Text;
using System.Threading.Tasks;
using Eco.Extensions;

namespace Eco.Serialization.Xml
{
    public class XmlAttributesGenerator : CommonAttributesGenerator
    {
        public static string GetXmlNamesapceForRootType(Type rootSettingsType)
        {
            return rootSettingsType.Name + ".xsd";
        }

        public override IEnumerable<string> GetAttributesTextFor(Type settingsType)
        {
            var attributesText = base.GetAttributesTextFor(settingsType);
            if (settingsType.IsDefined<RootAttribute>())
                attributesText = attributesText.Append(XmlClassAttributeTranslator.GetTextFor<XmlRootAttribute>(GetXmlNamesapceForRootType(settingsType)));

            return attributesText;
        }

        public override IEnumerable<string> GetAttributesTextFor(FieldInfo field, Usage defaultUsage)
        {
            var res = new List<string>(base.GetAttributesTextFor(field, defaultUsage));

            var fieldType = field.FieldType;
            if (field.IsPolimorphic() && !field.IsDefined<RefAttribute>() && !field.IsDefined<FieldMutatorAttribute>())
            {
                Type attributeType = fieldType.IsArray || field.IsDefined<InlineAttribute>() ? typeof(XmlArrayItemAttribute) : typeof(XmlElementAttribute);
                foreach (var t in field.GetKnownSerializableTypes())
                    res.Add(XmlFieldAttributeTranslator.GetTextFor(attributeType, t.GetNonGenericName()));
            }

            var attributes = field.GetCustomAttributes().ToArray();
            var attributesData = field.GetCustomAttributesData();
            for (int i = 0; i < attributes.Length; i++)
                res.Add(XmlFieldAttributeTranslator.Translate(attributes[i], attributesData[i], field));

            if (field.GetRawFieldType().IsSimple())
                res.Add(XmlFieldAttributeTranslator.GetTextFor<XmlAttributeAttribute>());

            return res;
        }
    }
}<commit_msg>Skip 'null' attributes<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Xml.Serialization;
using System.Text;
using System.Threading.Tasks;
using Eco.Extensions;

namespace Eco.Serialization.Xml
{
    public class XmlAttributesGenerator : CommonAttributesGenerator
    {
        public static string GetXmlNamesapceForRootType(Type rootSettingsType)
        {
            return rootSettingsType.Name + ".xsd";
        }

        public override IEnumerable<string> GetAttributesTextFor(Type settingsType)
        {
            var attributesText = base.GetAttributesTextFor(settingsType);
            if (settingsType.IsDefined<RootAttribute>())
                attributesText = attributesText.Append(XmlClassAttributeTranslator.GetTextFor<XmlRootAttribute>(GetXmlNamesapceForRootType(settingsType)));

            return attributesText;
        }

        public override IEnumerable<string> GetAttributesTextFor(FieldInfo field, Usage defaultUsage)
        {
            var res = new List<string>(base.GetAttributesTextFor(field, defaultUsage));

            var fieldType = field.FieldType;
            if (field.IsPolimorphic() && !field.IsDefined<RefAttribute>() && !field.IsDefined<FieldMutatorAttribute>())
            {
                Type attributeType = fieldType.IsArray || field.IsDefined<InlineAttribute>() ? typeof(XmlArrayItemAttribute) : typeof(XmlElementAttribute);
                foreach (var t in field.GetKnownSerializableTypes())
                    res.Add(XmlFieldAttributeTranslator.GetTextFor(attributeType, t.GetNonGenericName()));
            }

            var attributes = field.GetCustomAttributes().ToArray();
            var attributesData = field.GetCustomAttributesData();
            for (int i = 0; i < attributes.Length; i++)
                res.Add(XmlFieldAttributeTranslator.Translate(attributes[i], attributesData[i], field));

            if (field.GetRawFieldType().IsSimple())
                res.Add(XmlFieldAttributeTranslator.GetTextFor<XmlAttributeAttribute>());

            return res.Where(a => a != null);
        }
    }
}
{'fraction_non_alphanumeric': 0.09491445980782752, 'fraction_numerical': 0.00046871338176704945, 'mean_word_length': 3.049335863377609, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 22, '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': '667211', 'n_tokens_mistral': 1089, 'n_tokens_neox': 1055, 'n_words': 198}