<commit_before>using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using Umbraco.Core.Dynamics;
using Umbraco.Core.Models;
using umbraco.interfaces;

namespace Umbraco.Core
{
	/// <summary>
	/// Extension methods for IPublishedContent
	/// </summary>
	public static class PublishedContentExtensions
	{
		

		#region GetProperty
		public static IPublishedContentProperty GetProperty(this IPublishedContent content, string alias, bool recursive)
		{
			return content.GetPropertyRecursive(alias, recursive);
		}

		private static IPublishedContentProperty GetPropertyRecursive(this IPublishedContent content, string alias, bool recursive = false)
		{
			if (!recursive)
			{
				return content.GetProperty(alias);
			}
			var context = content;
			var prop = content.GetPropertyRecursive(alias);
			while (prop == null || prop.Value == null || prop.Value.ToString().IsNullOrWhiteSpace())
			{
				var parent = context.Parent;
				if (parent == null) break;
				prop = context.GetPropertyRecursive(alias);
			}
			return prop;
		} 
		#endregion

		#region GetPropertyValue
		public static string GetPropertyValue(this IPublishedContent doc, string alias)
		{
			return doc.GetPropertyValue(alias, false);
		}
		public static string GetPropertyValue(this IPublishedContent doc, string alias, string fallback)
		{
			var prop = doc.GetPropertyValue(alias);
			return !prop.IsNullOrWhiteSpace() ? prop : fallback;
		}
		public static string GetPropertyValue(this IPublishedContent doc, string alias, bool recursive)<commit_msg>Recursion was wrong on this one. Fixed #U4-1147<commit_after>using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using Umbraco.Core.Dynamics;
using Umbraco.Core.Models;
using umbraco.interfaces;

namespace Umbraco.Core
{
	/// <summary>
	/// Extension methods for IPublishedContent
	/// </summary>
	public static class PublishedContentExtensions
	{
		

		#region GetProperty
		public static IPublishedContentProperty GetProperty(this IPublishedContent content, string alias, bool recursive)
		{
			return content.GetPropertyRecursive(alias, recursive);
		}

		private static IPublishedContentProperty GetPropertyRecursive(this IPublishedContent content, string alias, bool recursive = false)
		{
			if (!recursive)
			{
				return content.GetProperty(alias);
			}
			var context = content;
			var prop = content.GetPropertyRecursive(alias);
			while (prop == null || prop.Value == null || prop.Value.ToString().IsNullOrWhiteSpace())
			{
                if (context.Parent == null) break;
                context = context.Parent;
                prop = context.GetPropertyRecursive(alias);
			}
			return prop;
		} 
		#endregion

		#region GetPropertyValue
		public static string GetPropertyValue(this IPublishedContent doc, string alias)
		{
			return doc.GetPropertyValue(alias, false);
		}
		public static string GetPropertyValue(this IPublishedContent doc, string alias, string fallback)
		{
			var prop = doc.GetPropertyValue(alias);
			return !prop.IsNullOrWhiteSpace() ? prop : fallback;
		}
		public static string GetPropertyValue(this IPublishedContent doc, string alias, bool recursive)
{'fraction_non_alphanumeric': 0.0887923005277864, 'fraction_numerical': 0.001552312946289972, 'mean_word_length': 4.247557003257329, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4731545', 'n_tokens_mistral': 1030, 'n_tokens_neox': 893, 'n_words': 249}