本文整理汇总了C#中SearchCriteria.HasFlag方法的典型用法代码示例。如果您正苦于以下问题:C# SearchCriteria.HasFlag方法的具体用法?C# SearchCriteria.HasFlag怎么用?C# SearchCriteria.HasFlag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SearchCriteria
的用法示例。
在下文中一共展示了SearchCriteria.HasFlag方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Search
public override List<SearchResult> Search(string input, SearchCriteria criteria)
{
List<SearchResult> results = new List<SearchResult>();
bool CaseSensitive = criteria.HasFlag(SearchCriteria.CaseSensitive);
bool Regex = criteria.HasFlag(SearchCriteria.RegularExpression);
string searchRegex = Regex ? input : Escape(input);
string searchText = null;
if(this.editor != null)
{
searchText = this.editor.Text;
}
else
{
searchText = GetSearchContent();
}
List<string> lines = new List<string>();
lines.AddRange(searchText.Split('\n'));
for(int i = 0; i < lines.Count; i++)
{
string line = lines[i];
MatchCollection matches = Matches(line, searchRegex);
foreach(Match match in matches)
{
results.Add(new SearchResult(i + 1, match.Index, match.Length, match.Value, line, this));
}
}
return results;
}
示例2: IsMatchAsync
/// <summary>
/// Determines whether <paramref name="file"/> is match the specified criterias.
/// </summary>
/// <returns><c>true</c> if this instance is match; otherwise, <c>false</c>.</returns>
/// <param name="file">File to check.</param>
/// <param name="searchCriteria">Search criteria.</param>
/// <param name="dateFrom">Date from.</param>
/// <param name="dateTo">Date to.</param>
/// <param name="keywords">Keywords.</param>
public async Task<bool> IsMatchAsync(string file, SearchCriteria searchCriteria, DateTime? dateFrom, DateTime? dateTo, string keywords)
{
if (file == null)
throw new ArgumentNullException("file");
if (!_file.Exists(file))
throw new FileNotFoundException(string.Format("File '{0}' doesn't exists.", file));
Log.D("Check if file '{0}' match the specified criterias.", file);
bool isMatch = true;
if (searchCriteria == SearchCriteria.None && dateFrom == null && dateTo == null)
{
Log.D("No criteria specified. File match.");
return true;
}
// Load meta data of file.
var fileMediaData = await _fileSystemHelper.GetFileMediaMetaDataAsync(file);
// Now check if criteria match.
isMatch = await IsMatchByDateAsync(fileMediaData, dateFrom, dateTo);
if (keywords != null)
{
if (searchCriteria.HasFlag(SearchCriteria.Tags)) isMatch = await IsMatchByTagsAsync(fileMediaData, keywords);
if (searchCriteria.HasFlag(SearchCriteria.Comments)) isMatch = await IsMatchByCommentsAsync(fileMediaData, keywords);
if (searchCriteria.HasFlag(SearchCriteria.Location)) isMatch = await IsMatchByLocationAsync(fileMediaData, keywords);
}
return isMatch;
}