Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overloaded IsOfTemplate methods #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/Sitecore.Commons/Extensions/ItemExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,42 @@ public static bool IsOfTemplate(this Item item, string templateId)
return (item.TemplateID.ToString() == templateId);
}

/// <summary>
/// check to verify that the item is of passed template
/// </summary>
/// <param name = "item"></param>
/// <param name = "templateId"></param>
/// <returns></returns>
public static bool IsOfTemplate(this Item item, ID templateId)
{
return item.IsOfTemplate(templateId.ToString());
}

/// <summary>
/// Will check the item's template, if deep is enabled it will check item's base templates
/// This signature should be avoided because of potential performance issues. If you MUST recurse along template inheritance prefer passing depth as an int and work to minimised its value
/// </summary>
/// <param name = "item"></param>
/// <param name = "templateId"></param>
/// <param name = "deep"></param>
/// <returns></returns>
public static bool IsOfTemplate(this Item item, ID templateId, bool deep)
{
return item.IsOfTemplate(templateId.ToString(), deep);
}

/// <summary>
/// Will check the item's template, if depth is non-zero it will recurse down the item's base templates
/// </summary>
/// <param name = "item"></param>
/// <param name = "templateId"></param>
/// <param name = "depth">0 = 'Do not recurse', -1 = 'recurse as far as system base template', n = 'recurse a maximum of n times'</param>
/// <returns></returns>
public static bool IsOfTemplate(this Item item, ID templateId, int depth)
{
return item.IsOfTemplate(templateId.ToString(), depth);
}

/// <summary>
/// Checks to see if an item is null
/// </summary>
Expand Down