Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I tried this way after defining a ForEachIndex extn. Have not tested it (duhh), should work I think.</p> <pre><code>public static FilterBase FilterFromPath(this Site activeSite, string filterPath) { //"Catalog Filters\Default Filters\SP3D Report Filters\Types of Reports\Equipment\Equipment Material Take-Off" Checks.IsNotNull(() =&gt; activeSite.ActivePlant); FilterFolder currentFolder = null; string plantFilters = CmnLocalizer.GetString(CmnResourceIDs.CmnFilterPlantFiltersFolder, "Plant Filters"); string catalogFilters = CmnLocalizer.GetString(CmnResourceIDs.CmnFilterCatalogFiltersFolder, "Catalog Filters"); if (filterPath.StartsWith(plantFilters)) currentFolder = activeSite.ActivePlant.PlantModel.Folders[0] as FilterFolder; else if (filterPath.StartsWith(catalogFilters)) currentFolder = activeSite.ActivePlant.PlantCatalog.Folders[0] as FilterFolder; else throw new ArgumentException("Invalid filter root specified. Should start with Plant or Catalog Filters"); IEnumerable&lt;string&gt; pathEntries = filterPath.Split(new string[] { @"\" }, StringSplitOptions.RemoveEmptyEntries).Skip(1); Checks.IsNotNull(() =&gt; pathEntries); if (pathEntries.Count() == 0) throw new ArgumentException("Invalid filter path specified"); int lastIndex = pathEntries.Count() - 1; FilterBase filterFound = null; pathEntries.ForEachIndex((item, index) =&gt; { if (index == lastIndex) { filterFound = currentFolder.ChildFilters.FirstOrDefault(f =&gt; f.Name.Equals(item)); if (filterFound.Equals(default(FilterBase))) throw new ArgumentException(string.Format("Filter '{0}' could not be found", item)); } else { currentFolder = currentFolder.ChildFolders.FirstOrDefault(f =&gt; f.Name.Equals(item)); if (currentFolder.Equals(default(FilterFolder))) throw new ArgumentException(string.Format("Folder '{0}' given in filter path not found", item)); } }); return filterFound; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload