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:
@@ -44,7 +44,7 @@ namespace Umbraco.Tests.PublishedContent
|
|||||||
InitializeInheritedContentTypes();
|
InitializeInheritedContentTypes();
|
||||||
|
|
||||||
var publishedContent = ctx.ContentCache.GetById(1100);
|
var publishedContent = ctx.ContentCache.GetById(1100);
|
||||||
Assert.That(publishedContent.IsDocumentType("inherited"));
|
Assert.That(publishedContent.IsDocumentType("inherited", false));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -53,7 +53,7 @@ namespace Umbraco.Tests.PublishedContent
|
|||||||
InitializeInheritedContentTypes();
|
InitializeInheritedContentTypes();
|
||||||
|
|
||||||
var publishedContent = ctx.ContentCache.GetById(1100);
|
var publishedContent = ctx.ContentCache.GetById(1100);
|
||||||
Assert.That(publishedContent.IsDocumentType("base"), Is.False);
|
Assert.That(publishedContent.IsDocumentType("base", false), Is.False);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|||||||
@@ -537,9 +537,27 @@ namespace Umbraco.Web
|
|||||||
|
|
||||||
#region Is Helpers
|
#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;
|
return true;
|
||||||
|
|
||||||
if (recursive)
|
if (recursive)
|
||||||
@@ -554,7 +572,7 @@ namespace Umbraco.Web
|
|||||||
while (type.ParentId > 0)
|
while (type.ParentId > 0)
|
||||||
{
|
{
|
||||||
type = contentTypeService.GetContentType(type.ParentId);
|
type = contentTypeService.GetContentType(type.ParentId);
|
||||||
if (type.Alias == docTypeAlias)
|
if (type.Alias.InvariantEquals(docTypeAlias))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user