本文整理汇总了C#中IFilter.Matches方法的典型用法代码示例。如果您正苦于以下问题:C# IFilter.Matches方法的具体用法?C# IFilter.Matches怎么用?C# IFilter.Matches使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFilter
的用法示例。
在下文中一共展示了IFilter.Matches方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EnumerateFileSystemEntries
/// <summary>
/// Returns a list of all files and subfolders found in the given folder.
/// The search is recursive.
/// </summary>
/// <param name="basepath">The folder to look in.</param>
/// <param name="filter">The filter to apply.</param>
/// <returns>A list of the full filenames and foldernames. Foldernames ends with the directoryseparator char</returns>
public static IEnumerable<string> EnumerateFileSystemEntries(string basepath, IFilter filter)
{
IFilter match;
filter = filter ?? new FilterExpression();
return EnumerateFileSystemEntries(basepath, (rootpath, path, attributes) => {
bool result;
if (!filter.Matches(path, out result, out match))
result = true;
return result;
});
}
示例2: Matches
/// <summary>
/// Utility function to match a filter with a default fall-through value
/// </summary>
/// <param name="filter">The filter to evaluate</param>
/// <param name="path">The path to evaluate</param>
/// <param name="match">The filter that matched</param>
public static bool Matches(IFilter filter, string path, out IFilter match)
{
if (filter == null || filter.Empty)
{
match = null;
return true;
}
bool result;
if (filter.Matches(path, out result, out match))
return result;
var includes = false;
var excludes = false;
Tuple<bool, bool> cacheLookup;
// Check for cached results
lock(_matchLock)
if (_matchFallbackLookup.TryGetValue(filter, out cacheLookup))
{
includes = cacheLookup.Item1;
excludes = cacheLookup.Item2;
}
// Figure out what components are in the filter
if (cacheLookup == null)
{
var q = new Queue<IFilter>();
q.Enqueue(filter);
while (q.Count > 0)
{
var p = q.Dequeue();
if (p == null || p.Empty)
continue;
else if (p is FilterExpression)
{
if (((FilterExpression)p).Result)
includes = true;
else
excludes = true;
}
else if (p is JoinedFilterExpression)
{
q.Enqueue(((JoinedFilterExpression)p).First);
q.Enqueue(((JoinedFilterExpression)p).Second);
}
}
// Populate the cache
lock(_matchLock)
{
if (_matchFallbackLookup.Count > 10)
_matchFallbackLookup.Remove(_matchFallbackLookup.Keys.Skip(new Random().Next(0, _matchFallbackLookup.Count)).First());
_matchFallbackLookup[filter] = new Tuple<bool, bool>(includes, excludes);
}
}
match = null;
// We have only include filters, we exclude files by default
if (includes && !excludes)
{
return path.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString());
}
// Otherwise we include by default
else
{
return true;
}
}
示例3: Matches
/// <summary>
/// Utility function to match a filter with a default fall-through value
/// </summary>
/// <param name="filter">The filter to evaluate</param>
/// <param name="path">The path to evaluate</param>
/// <param name="match">The filter that matched</param>
public static bool Matches(IFilter filter, string path, out IFilter match)
{
if (filter == null || filter.Empty)
{
match = null;
return true;
}
bool result;
if (filter.Matches(path, out result, out match))
return result;
bool includes;
bool excludes;
AnalyzeFilters(filter, out includes, out excludes);
match = null;
// We have only include filters, we exclude files by default
if (includes && !excludes)
{
return false;
}
// Otherwise we include by default
else
{
return true;
}
}
示例4: Matches
/// <summary>
/// Utility function to match a filter with a default fall-through value
/// </summary>
/// <param name="filter">The filter to evaluate</param>
/// <param name="path">The path to evaluate</param>
/// <param name="match">The filter that matched</param>
public static bool Matches(IFilter filter, string path, out IFilter match)
{
if (filter == null || filter.Empty)
{
match = null;
return true;
}
bool result;
if (filter.Matches(path, out result, out match))
return result;
// If we only exclude files, choose to include by default
var q = new Queue<IFilter>();
q.Enqueue(filter);
// TODO: We should cache this, so we do not compute it every time
while (q.Count > 0)
{
var p = q.Dequeue();
if (p == null || p.Empty)
continue;
else if (p is FilterExpression && ((FilterExpression)p).Result)
{
match = p;
return false; // We have an include filter, so we exclude by default
}
else if (p is JoinedFilterExpression)
{
q.Enqueue(((JoinedFilterExpression)p).First);
q.Enqueue(((JoinedFilterExpression)p).Second);
}
}
// Only excludes, we return true
match = null;
return true;
}