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.
This commit is contained in:
Lars-Erik Aabech
2013-10-16 11:38:58 +02:00
parent b6777e4635
commit a1ef40e4be
2 changed files with 23 additions and 5 deletions

View File

@@ -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]

View File

@@ -537,9 +537,27 @@ namespace Umbraco.Web
#region Is Helpers
public static bool IsDocumentType(this IPublishedContent content, string docTypeAlias, bool recursive = false)
/// <summary>
/// Determines whether the specified content is a specified content type.
/// </summary>
/// <param name="content">The content to determine content type of.</param>
/// <param name="docTypeAlias">The alias of the content type to test against.</param>
/// <returns>True if the content is of the specified content type; otherwise false.</returns>
public static bool IsDocumentType(this IPublishedContent content, string docTypeAlias)
{
return content.DocumentTypeAlias.InvariantEquals(docTypeAlias);
}
/// <summary>
/// Determines whether the specified content is a specified content type or it's derived types.
/// </summary>
/// <param name="content">The content to determine content type of.</param>
/// <param name="docTypeAlias">The alias of the content type to test against.</param>
/// <param name="recursive">When true, recurses up the content type tree to check inheritance; when false just calls IsDocumentType(this IPublishedContent content, string docTypeAlias).</param>
/// <returns>True if the content is of the specified content type or a derived content type; otherwise false.</returns>
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;