Items enumeration

The first method that the Windows Shell will call in your ShellBoost namespace extension is the EnumItems method. Here is a simple example of such a method, that we saw in the “Writing your first extension” chapter):

public override IEnumerable<ShellItem> EnumItems(SHCONTF options)
{
    yield return new ShellFolder(this, new StringKeyShellItemId("My First Folder"));
    yield return new ShellItem(this, new StringKeyShellItemId("My First Item"));
}

This EnumItems method simply tells the Shell what Shell Items a given Shell Folder contains. However, it’s also used by ShellBoost when the Shell asks for one single item (for direct access, parsing, searching, etc.). For this reason, the ShellFolder class defines the two following methods that are called in these cases:

    /// Gets an item using its display name.
    protected virtual ShellItem GetItem(string displayName)
    {
        ... pseudo code
        return EnumItems(SHCONTF.SHCONTF_FOLDERS |
            SHCONTF.SHCONTF_NONFOLDERS |
            SHCONTF.SHCONTF_FLATLIST | // all items
            SHCONTF.SHCONTF_INCLUDEHIDDEN |
            SHCONTF.SHCONTF_INCLUDESUPERHIDDEN)?.FirstOrDefault(i => i.DisplayName.EqualsIgnoreCase(displayName));
    }
 
    /// Gets an item using its identifier.
    public virtual ShellItem GetItem(ShellItemId id)
    {
        ... pseudo code
        return EnumItems(SHCONTF.SHCONTF_FOLDERS |
            SHCONTF.SHCONTF_NONFOLDERS |
            SHCONTF.SHCONTF_FLATLIST | // all items
            SHCONTF.SHCONTF_INCLUDEHIDDEN |
            SHCONTF.SHCONTF_INCLUDESUPERHIDDEN)?.FirstOrDefault(i => i != null && i.Id != null && i.Id.EqualsOrSameBeginning(id));
    }

This is obviously not optimal, so it’s recommended you override both these methods if your Shell Folder implementation must maximize performance.