From a1ef40e4beec7e69cf01025f14e831e5e9db648c Mon Sep 17 00:00:00 2001 From: Lars-Erik Aabech Date: Wed, 16 Oct 2013 11:38:58 +0200 Subject: [PATCH] Split the recursive IsDocumentType into an overload for "real" backwards compatibility. Changed string comparison to use InvariantEquals. (guessing it doesn't _really_ break backw. compat?) Added XML docs. --- .../PublishedContentExtensionTests.cs | 4 ++-- src/Umbraco.Web/PublishedContentExtensions.cs | 24 ++++++++++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentExtensionTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentExtensionTests.cs index 249256cc50..98ee00c2cd 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentExtensionTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentExtensionTests.cs @@ -44,7 +44,7 @@ namespace Umbraco.Tests.PublishedContent InitializeInheritedContentTypes(); var publishedContent = ctx.ContentCache.GetById(1100); - Assert.That(publishedContent.IsDocumentType("inherited")); + Assert.That(publishedContent.IsDocumentType("inherited", false)); } [Test] @@ -53,7 +53,7 @@ namespace Umbraco.Tests.PublishedContent InitializeInheritedContentTypes(); var publishedContent = ctx.ContentCache.GetById(1100); - Assert.That(publishedContent.IsDocumentType("base"), Is.False); + Assert.That(publishedContent.IsDocumentType("base", false), Is.False); } [Test] diff --git a/src/Umbraco.Web/PublishedContentExtensions.cs b/src/Umbraco.Web/PublishedContentExtensions.cs index 086cf1ad5a..ce900702a1 100644 --- a/src/Umbraco.Web/PublishedContentExtensions.cs +++ b/src/Umbraco.Web/PublishedContentExtensions.cs @@ -537,9 +537,27 @@ namespace Umbraco.Web #region Is Helpers - public static bool IsDocumentType(this IPublishedContent content, string docTypeAlias, bool recursive = false) + /// + /// Determines whether the specified content is a specified content type. + /// + /// The content to determine content type of. + /// The alias of the content type to test against. + /// True if the content is of the specified content type; otherwise false. + public static bool IsDocumentType(this IPublishedContent content, string docTypeAlias) + { + return content.DocumentTypeAlias.InvariantEquals(docTypeAlias); + } + + /// + /// Determines whether the specified content is a specified content type or it's derived types. + /// + /// The content to determine content type of. + /// The alias of the content type to test against. + /// When true, recurses up the content type tree to check inheritance; when false just calls IsDocumentType(this IPublishedContent content, string docTypeAlias). + /// True if the content is of the specified content type or a derived content type; otherwise false. + public static bool IsDocumentType(this IPublishedContent content, string docTypeAlias, bool recursive) { - if (content.DocumentTypeAlias == docTypeAlias) + if (content.IsDocumentType(docTypeAlias)) return true; if (recursive) @@ -554,7 +572,7 @@ namespace Umbraco.Web while (type.ParentId > 0) { type = contentTypeService.GetContentType(type.ParentId); - if (type.Alias == docTypeAlias) + if (type.Alias.InvariantEquals(docTypeAlias)) return true; } return false;