예제 #1
0
        /// <summary>
        /// Searches for a pattern in each metadata tag and returns the result as a list.
        /// </summary>
        /// <param name="searchPattern">The regular expression to use for the search.</param>
        /// <param name="flags">A bitfield that controls which fields should be searched in.</param>
        /// <returns>A list containing all found metadata tags.</returns>
        /// <exception cref="ArgumentNullException">
        /// <typeparamref name="searchPattern"/> is null.</exception>
        /// <exception cref="ArgumentException">
        /// <typeparamref name="searchPattern"/> is empty.</exception>
        public List <MetadataTag> RegexSearch(string searchPattern, MD_SEARCH_FLAGS flags)
        {
            if (searchPattern == null)
            {
                throw new ArgumentNullException("searchString");
            }
            if (searchPattern.Length == 0)
            {
                throw new ArgumentException("searchString is empty");
            }
            List <MetadataTag> result = new List <MetadataTag>(Count);
            Regex regex             = new Regex(searchPattern);
            List <MetadataTag> list = List;

            foreach (MetadataTag tag in list)
            {
                if (((flags & MD_SEARCH_FLAGS.KEY) > 0) && regex.Match(tag.Key).Success)
                {
                    result.Add(tag);
                    continue;
                }
                if (((flags & MD_SEARCH_FLAGS.DESCRIPTION) > 0) && regex.Match(tag.Description).Success)
                {
                    result.Add(tag);
                    continue;
                }
                if (((flags & MD_SEARCH_FLAGS.TOSTRING) > 0) && regex.Match(tag.ToString()).Success)
                {
                    result.Add(tag);
                    continue;
                }
            }
            result.Capacity = result.Count;
            return(result);
        }
예제 #2
0
 /// <summary>
 /// Searches for a pattern in each metadata tag and returns the result as a list.
 /// </summary>
 /// <param name="searchPattern">The regular expression to use for the search.</param>
 /// <param name="flags">A bitfield that controls which fields should be searched in.</param>
 /// <returns>A list containing all found metadata tags.</returns>
 /// <exception cref="ArgumentNullException">
 /// <typeparamref name="searchPattern"/> is null.</exception>
 /// <exception cref="ArgumentException">
 /// <typeparamref name="searchPattern"/> is empty.</exception>
 public List<MetadataTag> RegexSearch(string searchPattern, MD_SEARCH_FLAGS flags)
 {
     if (searchPattern == null)
     {
         throw new ArgumentNullException("searchString");
     }
     if (searchPattern.Length == 0)
     {
         throw new ArgumentException("searchString is empty");
     }
     List<MetadataTag> result = new List<MetadataTag>(Count);
     Regex regex = new Regex(searchPattern);
     List<MetadataTag> list = List;
     foreach (MetadataTag tag in list)
     {
         if (((flags & MD_SEARCH_FLAGS.KEY) > 0) && regex.Match(tag.Key).Success)
         {
             result.Add(tag);
             continue;
         }
         if (((flags & MD_SEARCH_FLAGS.DESCRIPTION) > 0) && regex.Match(tag.Description).Success)
         {
             result.Add(tag);
             continue;
         }
         if (((flags & MD_SEARCH_FLAGS.TOSTRING) > 0) && regex.Match(tag.ToString()).Success)
         {
             result.Add(tag);
             continue;
         }
     }
     result.Capacity = result.Count;
     return result;
 }