There is an OOTB call that handles this now.
protected virtual bool InheritsTemplate(Item candidate, string templateIdentifier)
{
if (candidate == null || string.IsNullOrEmpty(templateIdentifier))
return false;
var t = TemplateManager.GetTemplate(candidate);
var y = TemplateManager.GetTemplate(templateIdentifier, candidate.Database);
if (y == null)
throw new Exception($"Invalid Template Identifier: \'{templateIdentifier}\'");
return t.InheritsFrom(y.ID);
}
The important parts of this code being:
// Get the template of the Item you want to check
var t = TemplateManager.GetTemplate(candidate);
// Get the template you want to check for
var y = TemplateManager.GetTemplate(templateIdentifier, candidate.Database);
// then use the OOTB call
t.InheritsFrom(y.ID)
templateIdentifier
could be anything you can normally send to Sitecore; e.g. an ID or a template path user defined/common folder
or whatever.