<commit_before>﻿using System;
using System.Xml.Linq;
using NConfig.ConfigurationDataProviders;
using NConfig.XML;

namespace NConfig
{
    public static class ConfigureXmlExtensions
    {
        public static INConfigSettings AddFromXmlFile(this INConfigSettings source, string fileName)
        {
            source.AddConfigurationDataProvider(new ConvertFromSectionDataProvider(()=>
                new XmlLoader().LoadFile(fileName), source));

            return source;
        }

        public static INConfigSettings AddFromRawXml(this INConfigSettings source, string rawXml)
        {
            source.AddConfigurationDataProvider(new ConvertFromSectionDataProvider(()=>
                new XmlLoader().ReadXml(rawXml), source));
            return source;
        }

        public static string GetAttributeValueOrNull(this XElement source, string attributeName)
        {
            var result = source.GetAttributeValueOrNullByExactName(attributeName);
            if (result == null)
            {
                result = source.GetAttributeValueOrNullByExactName(attributeName);
            }
            return result;
        }

        public static string GetAttributeValueOrThrow(this XElement source, string attributeName)
        {
            var result = source.GetAttributeValueOrNull(attributeName);
            
            if (result == null)
            {
                throw new ArgumentException(string.Format("Expected attribute {0} was not found on node: {1}",attributeName, source.Name));
            }

            return result;
        }
        public static void SetAttributeValueIfNotNullOrEmpty(this XElement source, string attributeName, string value)
        {
            if (!string.IsNullOrEmpty(value))
            {
                source.SetAttributeValue(attributeName, value);
            }
        }
        public static void SetAttributeValueOrThrow(this XElement source, string attributeName, string value)
        {
            if (!string.IsNullOrEmpty(value))
            {
                source.SetAttributeValue(attributeName, value);
            }
            else
            {
                throw new ArgumentException(string.Format("Property {0} cannot be null ", attributeName));
            }
        }

        private static string GetAttributeValueOrNullByExactName(this XElement source, string attributeName)
        {
            if (source.Attribute(attributeName) != null)
            {
                return source.Attribute(attributeName).Value;
            }

            return null;
        }
    }
}
<commit_msg>some code cleanup<commit_after>﻿using System;
using System.Xml.Linq;
using NConfig.ConfigurationDataProviders;
using NConfig.XML;

namespace NConfig
{
    public static class ConfigureXmlExtensions
    {
        public static INConfigSettings AddFromXmlFile(this INConfigSettings source, string fileName)
        {
            source.AddConfigurationDataProvider(new ConvertFromSectionDataProvider(()=>
                new XmlLoader().LoadFile(fileName), source));

            return source;
        }

        public static INConfigSettings AddFromRawXml(this INConfigSettings source, string rawXml)
        {
            source.AddConfigurationDataProvider(new ConvertFromSectionDataProvider(()=>
                new XmlLoader().ReadXml(rawXml), source));
            return source;
        }

        public static string GetAttributeValueOrNull(this XElement source, string attributeName)
        {
            return source.GetAttributeValueOrNullByExactName(attributeName);
        }

        public static string GetAttributeValueOrThrow(this XElement source, string attributeName)
        {
            var result = source.GetAttributeValueOrNull(attributeName);
            
            if (result == null)
            {
                throw new ArgumentException(string.Format("Expected attribute {0} was not found on node: {1}",attributeName, source.Name));
            }

            return result;
        }
        public static void SetAttributeValueIfNotNullOrEmpty(this XElement source, string attributeName, string value)
        {
            if (!string.IsNullOrEmpty(value))
            {
                source.SetAttributeValue(attributeName, value);
            }
        }
        public static void SetAttributeValueOrThrow(this XElement source, string attributeName, string value)
        {
            if (!string.IsNullOrEmpty(value))
            {
                source.SetAttributeValue(attributeName, value);
            }
            else
            {
                throw new ArgumentException(string.Format("Property {0} cannot be null ", attributeName));
            }
        }

        private static string GetAttributeValueOrNullByExactName(this XElement source, string attributeName)
        {
            if (source.Attribute(attributeName) != null)
            {
                return source.Attribute(attributeName).Value;
            }

            return null;
        }
    }
}

{'fraction_non_alphanumeric': 0.0713150576082638, 'fraction_numerical': 0.0011918951132300357, 'mean_word_length': 2.0870631514408338, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4537777', 'n_tokens_mistral': 1170, 'n_tokens_neox': 1146, 'n_words': 280}