<commit_before>﻿using System;
using System.Xml;
using System.Xml.Linq;

namespace Umbraco.Core.Models
{
    public static class PropertyExtensions
    {
        /// <summary>
        /// Creates the xml representation for the <see cref="Property"/> object
        /// </summary>
        /// <param name="property"><see cref="Property"/> to generate xml for</param>
        /// <returns>Xml of the property and its value</returns>
        public static XElement ToXml(this Property property)
        {
            string nodeName = property.Alias.ToUmbracoAlias(StringAliasCaseType.CamelCase, true);

            var xd = new XmlDocument();
            XmlNode xmlNode = xd.CreateNode(XmlNodeType.Element, nodeName, "");

            XmlNode child = property.PropertyType.DataTypeDatabaseType == DataTypeDatabaseType.Ntext
                                ? xd.CreateCDataSection(property.Value.ToString()) as XmlNode
                                : xd.CreateTextNode(property.Value.ToString());

            xmlNode.AppendChild(child);

            //This seems to fail during testing 
            //xmlNode.AppendChild(property.PropertyType.DataType(property.Id).Data.ToXMl(xd));
            
            var element = xmlNode.GetXElement();
            return element;
        }
    }
}<commit_msg>Adding comment<commit_after>﻿using System;
using System.Xml;
using System.Xml.Linq;

namespace Umbraco.Core.Models
{
    public static class PropertyExtensions
    {
        /// <summary>
        /// Creates the xml representation for the <see cref="Property"/> object
        /// </summary>
        /// <param name="property"><see cref="Property"/> to generate xml for</param>
        /// <returns>Xml of the property and its value</returns>
        public static XElement ToXml(this Property property)
        {
            string nodeName = property.Alias.ToUmbracoAlias(StringAliasCaseType.CamelCase, true);

            var xd = new XmlDocument();
            XmlNode xmlNode = xd.CreateNode(XmlNodeType.Element, nodeName, "");

            XmlNode child = property.PropertyType.DataTypeDatabaseType == DataTypeDatabaseType.Ntext
                                ? xd.CreateCDataSection(property.Value.ToString()) as XmlNode
                                : xd.CreateTextNode(property.Value.ToString());

            xmlNode.AppendChild(child);
            //TODO Revisit this by correcting test setup or refactoring DefaultData class to use PetaPoco instead of SqlHelper.
            //This seems to fail during testing 
            //xmlNode.AppendChild(property.PropertyType.DataType(property.Id).Data.ToXMl(xd));
            
            var element = xmlNode.GetXElement();
            return element;
        }
    }
}
{'fraction_non_alphanumeric': 0.10146520146520147, 'fraction_numerical': 0.0, 'mean_word_length': 2.1792782305005822, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, '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': '5991987', 'n_tokens_mistral': 706, 'n_tokens_neox': 685, 'n_words': 170}