/// <summary> /// Searches for a configuration node which best matches the specified <paramref name="searchMatcher"/> /// in the given <paramref name="startNode"/> and subnodes. /// </summary> /// <param name="startNode">Node to search through.</param> /// <param name="searchMatcher">Pattern which does the matching.</param> /// <param name="bestMatch">Location of the best matching configuration node for the /// search value.</param> /// <param name="bestScore">Score of the best match.</param> /// <returns>Enumeration of matching configuration nodes.</returns> protected static ICollection<IConfigurationNode> Search(IConfigurationNode startNode, ConfigObjectSearchMatcher searchMatcher, out IConfigurationNode bestMatch, out float bestScore) { bestMatch = null; List<IConfigurationNode> result = new List<IConfigurationNode>(); // Check current node (the node may have no config object assigned if it is the root node or // if we have a section in use which was not defined) bestScore = startNode.ConfigObj == null ? 0 : searchMatcher.CalculateMatchQuality(startNode.ConfigObj); if (bestScore > 0) { bestMatch = startNode; result.Add(startNode); } // Check children foreach (ConfigurationNode childNode in startNode.ChildNodes) { IConfigurationNode match; float score; result.AddRange(Search(childNode, searchMatcher, out match, out score)); if (score > bestScore) { bestMatch = match; bestScore = score; } } return result; }
public SearchResult Search(string searchText) { CheckInitialized(); float score; ConfigObjectSearchMatcher searchMatcher = new ConfigObjectSearchMatcher(searchText); IConfigurationNode bestMatch; ICollection <IConfigurationNode> matches = Search(_tree.RootNode, searchMatcher, out bestMatch, out score); return(new SearchResult(matches, bestMatch)); }
public SearchResult Search(string searchText) { CheckInitialized(); float score; ConfigObjectSearchMatcher searchMatcher = new ConfigObjectSearchMatcher(searchText); IConfigurationNode bestMatch; ICollection<IConfigurationNode> matches = Search(_tree.RootNode, searchMatcher, out bestMatch, out score); return new SearchResult(matches, bestMatch); }
/// <summary> /// Searches for a configuration node which best matches the specified <paramref name="searchMatcher"/> /// in the given <paramref name="startNode"/> and subnodes. /// </summary> /// <param name="startNode">Node to search through.</param> /// <param name="searchMatcher">Pattern which does the matching.</param> /// <param name="bestMatch">Location of the best matching configuration node for the /// search value.</param> /// <param name="bestScore">Score of the best match.</param> /// <returns>Enumeration of matching configuration nodes.</returns> protected static ICollection <IConfigurationNode> Search(IConfigurationNode startNode, ConfigObjectSearchMatcher searchMatcher, out IConfigurationNode bestMatch, out float bestScore) { bestMatch = null; List <IConfigurationNode> result = new List <IConfigurationNode>(); // Check current node (the node may have no config object assigned if it is the root node or // if we have a section in use which was not defined) bestScore = startNode.ConfigObj == null ? 0 : searchMatcher.CalculateMatchQuality(startNode.ConfigObj); if (bestScore > 0) { bestMatch = startNode; result.Add(startNode); } // Check children foreach (ConfigurationNode childNode in startNode.ChildNodes) { IConfigurationNode match; float score; result.AddRange(Search(childNode, searchMatcher, out match, out score)); if (score > bestScore) { bestMatch = match; bestScore = score; } } return(result); }