Fortis-Collection / fortis

A framework for creating a strongly typed model based on Sitecore templates and the Sitecore API

Home Page:http://fortis.ws

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ItemFactory.SelectChildRecursive<T>() does not behave as expected

johnduhart opened this issue · comments

Correct me if I'm wrong, but I would expect that:

_itemFactory.SelectChildRecursive<IAnalyticsSettings>("/folder1/folder2/item")

would behave the same as:

_itemFactory.SelectChildrenRecursive<IAnalyticsSettings>("/folder1/folder2/item").FirstOrDefault()

But, it doesn't. Because folder1 doesn't contain an IAnalyticsSettings item, the method never enumerates over folder1's children.

Let me know if I'm correct and I'll submit a PR to fix it.

That doesn't sound quite right. The first thing that SelectChildRecursive does is get all the child items of the path, so that would start with all the children of /folder1/folder2/item - it doesn't matter what is in folder1

However, if item does not contain any IAnalyticsSettings, it will not recurse down the tree as it already filters the child items by the T passed in.

I think this method:

public virtual T SelectChildRecursive<T>(Guid id) where T : IItemWrapper
{
    return SelectChildRecursive<T>(SelectChildren<T>(id));
}

should probably change to this:

public virtual T SelectChildRecursive<T>(Guid id) where T : IItemWrapper
{
    return SelectChildRecursive<T>(SelectChildren<IItemWrapper>(id));
}

The SelectChildRecursive<T> would then filter out the items that do not match the type.

Ah, you're right, the path in my example should of been "/folder1". In reality I want to find the IAnalyticsSettings at "/folder1/folder2/item", but as you mention that won't happen.

Pull request incoming.

Released with 4.2.1