本文整理汇总了C#中Predicate类的典型用法代码示例。如果您正苦于以下问题:C# Predicate类的具体用法?C# Predicate怎么用?C# Predicate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Predicate类属于命名空间,在下文中一共展示了Predicate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NewCriterion
internal static AssemblyLoaderPathNameCriterion NewCriterion(Predicate predicate)
{
if (predicate == null)
throw new ArgumentNullException("predicate");
return new AssemblyLoaderPathNameCriterion(predicate);
}
示例2: InitializeButtonState
public void InitializeButtonState(Mubox.Configuration.KeySettingCollection keySettings, Predicate<Mubox.Configuration.KeySetting> filterCallback, Action<Mubox.Configuration.KeySetting> enableCallback, Action<Mubox.Configuration.KeySetting> disableCallback)
{
this.KeySettings = keySettings;
this.FilterCallback = filterCallback;
this.EnableCallback = enableCallback;
this.DisableCallback = disableCallback;
ProcessFrameworkElementTree(this, (Action<FrameworkElement>)delegate(FrameworkElement frameworkElement)
{
try
{
System.Windows.Controls.Primitives.ToggleButton toggleButton = frameworkElement as System.Windows.Controls.Primitives.ToggleButton;
if (toggleButton != null)
{
Mubox.Configuration.KeySetting keySetting;
toggleButton.IsChecked =
KeySettings.TryGetKeySetting((WinAPI.VK)Enum.Parse(typeof(WinAPI.VK), toggleButton.Tag as string, true), out keySetting)
&& FilterCallback(keySetting);
}
}
catch (Exception ex)
{
ex.Log();
}
});
}
示例3: ReadInMemory
public static void ReadInMemory(FileInfo zipFileName, Predicate<ZipEntry> filter, Action<MemoryStream> action)
{
using (ZipInputStream inputStream = new ZipInputStream(zipFileName.OpenRead()))
{
ZipEntry entry;
while ((entry = inputStream.GetNextEntry()) != null)
{
if (filter(entry))
{
using (MemoryStream stream = new MemoryStream())
{
int count = 0x800;
byte[] buffer = new byte[0x800];
if (entry.Size <= 0L)
{
goto Label_0138;
}
Label_0116:
count = inputStream.Read(buffer, 0, buffer.Length);
if (count > 0)
{
stream.Write(buffer, 0, count);
goto Label_0116;
}
Label_0138:
stream.Position = 0;
action(stream);
}
}
}
}
}
示例4: MapWhen
/// <summary>
/// Branches the request pipeline based on the result of the given predicate.
/// </summary>
/// <param name="app"></param>
/// <param name="predicate">Invoked with the request environment to determine if the branch should be taken</param>
/// <param name="configuration">Configures a branch to take</param>
/// <returns></returns>
public static IApplicationBuilder MapWhen(this IApplicationBuilder app, Predicate predicate, Action<IApplicationBuilder> configuration)
{
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
if (predicate == null)
{
throw new ArgumentNullException(nameof(predicate));
}
if (configuration == null)
{
throw new ArgumentNullException(nameof(configuration));
}
// create branch
var branchBuilder = app.New();
configuration(branchBuilder);
var branch = branchBuilder.Build();
// put middleware in pipeline
var options = new MapWhenOptions
{
Predicate = predicate,
Branch = branch,
};
return app.Use(next => new MapWhenMiddleware(next, options).Invoke);
}
示例5: ActionCommand
public ActionCommand(Action<Object> execute, Predicate<Object> canExecute = null)
{
if (execute == null) throw new ArgumentNullException(nameof(execute));
this.execute = execute;
this.canExecute = canExecute ?? (parameter => true);
}
示例6: Response
/// <summary>
/// Constructs a new Response with the specified properties.
/// </summary>
/// <param name="rule">The rule used to decide if the response should be returned.</param>
/// <param name="message">A function that builds the HttpResponseMessage to be returned.</param>
public Response(Predicate<Request> rule, Func<HttpResponseMessage> message)
{
if (message == null) throw new ArgumentNullException("message");
Rule = rule;
Message = message;
}
示例7: LoadingWork
private void LoadingWork(Predicate<IDataReader> readWhile = null)
{
if (readWhile == null)
{
readWhile = r => true;
}
var index = 0;
if (_Reader.Read())
{
var columns = _Reader.GetColumnNames();
do
{
if (!readWhile(_Reader))
{
break;
}
_LoadedRows.Add(new DataRow(index++)
{
ColumnNames = columns,
Values = _Reader.GetValues()
});
} while (_Reader.Read());
}
_LoadedRows.CompleteAdding();
_Reader.Close();
}
示例8: CremationTarget
public CremationTarget(string label, Predicate<Thing> p, int naturalPriority, Droid c)
{
this.label = label;
this.naturalPriority = naturalPriority;
this.Accepts = p;
this.crematorius = c;
}
示例9: GetFilteredTypesFromAssemblies
/// <summary>
/// 获取当前项目中满足指定条件的类型集合
/// 首先从缓存文件中查询,若无缓存则遍历所有引用的程序集,并最后保存到缓存文件中
/// </summary>
/// <param name="cacheName">缓存文件名</param>
/// <param name="predicate">类型匹配的规则(一个委托)</param>
/// <param name="buildManager">操作类型缓存的组件</param>
/// <returns>匹配的类型集合</returns>
public static List<Type> GetFilteredTypesFromAssemblies(string cacheName, Predicate<Type> predicate, IBuildManager buildManager)
{
//类型缓存序列化器
TypeCacheSerializer serializer = new TypeCacheSerializer();
//首先从本地磁盘读取缓存路由的缓存文件,获取缓存的区域路由的类型集合
// first, try reading from the cache on disk
List<Type> matchingTypes = ReadTypesFromCache(cacheName, predicate, buildManager, serializer);
if (matchingTypes != null)
{
return matchingTypes;
}
//如果没有读取到路由的缓存信息,则枚举每一个程序集寻找匹配的类型
//即寻找继承了AreaRegistration的类,并且包含无参构造函数
// if reading from the cache failed, enumerate over every assembly looking for a matching type
matchingTypes = FilterTypesInAssemblies(buildManager, predicate).ToList();
// 将类型信息保存到XML文件中作为缓存
// C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\985b57d0\89016edd\UserCache\MVC-AreaRegistrationTypeCache.xml
// finally, save the cache back to disk
SaveTypesToCache(cacheName, matchingTypes, buildManager, serializer);
return matchingTypes;
}
示例10: DelegateCommand
/// <summary>
/// Initializes a new instance of the command.
/// </summary>
/// <param name="canExecuteDelegate">Checks whether the command can be executed
/// or not. This delegate is being invoked if <see cref="CanExecute"/> is being
/// called. Might be null in order to always enable the command.</param>
/// <param name="executeDelegate">An action that is being invoked if the command
/// executes (<see cref="Execute"/> is being invoked).</param>
/// <exception cref="ArgumentNullException">If <paramref name="executeDelegate"/>
/// is a null reference.</exception>
public DelegateCommand(Predicate<object> canExecuteDelegate, Action<object> executeDelegate)
{
if (executeDelegate == null) throw new ArgumentNullException("executeDelegate");
ExecuteAction = executeDelegate;
CanExecutePredicate = canExecuteDelegate;
}
示例11: Find
public static FrameworkElement Find(this DependencyObject parent, Predicate<FrameworkElement> predicate)
{
if (parent is FrameworkElement)
if (predicate((FrameworkElement)parent))
return (FrameworkElement)parent;
foreach (var child in GetChildren(parent))
{
try
{
var childElement = child as FrameworkElement;
if (childElement != null)
if (predicate(childElement))
return childElement;
else
{
var result = childElement.Find(predicate);
if (result != null)
return result;
}
}
catch { }
}
return null;
}
示例12: AssembliesFromPath
// TODO -- this is so common here and in FubuMVC, just get something into FubuCore
public static IEnumerable<Assembly> AssembliesFromPath(string path, Predicate<Assembly> assemblyFilter)
{
var assemblyPaths = Directory.GetFiles(path)
.Where(file =>
Path.GetExtension(file).Equals(
".exe",
StringComparison.OrdinalIgnoreCase)
||
Path.GetExtension(file).Equals(
".dll",
StringComparison.OrdinalIgnoreCase));
foreach (string assemblyPath in assemblyPaths)
{
Assembly assembly =
AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(
x => x.GetName().Name == Path.GetFileNameWithoutExtension(assemblyPath));
if (assembly == null)
{
try
{
assembly = Assembly.LoadFrom(assemblyPath);
}
catch
{
}
}
if (assembly != null && assemblyFilter(assembly))
{
yield return assembly;
}
}
}
示例13: FlvParser
public FlvParser(Stream stream, Predicate<FlvTag> exec)
{
FLVHeader header = FLVHeader.ReadHeader(stream);
if (!header.IsFlv) {
this.IsFlv = false;
return;
}
this.IsFlv = true;
stream.Seek(header.Length, SeekOrigin.Begin);
Tags = new List<FlvTag>();
FlvTag tag;
while ((tag = FlvTag.ReadTag(stream)) != null) {
if (tag is ScriptTag) {
this.MetaTag = tag as ScriptTag;
}
Tags.Add(tag);
if (Duration < tag.TimeStamp)
Duration = tag.TimeStamp;
if (exec != null) {
if (!exec(tag)) {
break;
}
}
}
if (Tags.Count > 1) {
this.Length = stream.Length - Tags[1].Offset + 11; //+ FlvMain.c_HeaderSize;
this.Rate = (this.Duration == 0 ? 0 : this.Length * 8 / this.Duration);
}
}
示例14: ViewsCollection
/// <summary>
/// Initializes a new instance of <see cref="ViewsCollection"/>.
/// </summary>
/// <param name="list">The list to wrap and filter.</param>
/// <param name="filter">A predicate to filter the <paramref name="list"/> collection.</param>
public ViewsCollection(ObservableCollection<ItemMetadata> list, Predicate<ItemMetadata> filter)
{
this.subjectCollection = list;
this.filter = filter;
Initialize();
subjectCollection.CollectionChanged += UnderlyingCollection_CollectionChanged;
}
示例15: Rule
public Rule(Parser parser, RuleType ruleType, Predicate<Parser> lookAhead, RuleDelegate evaluate)
{
_parser = parser;
_ruleType = ruleType;
_lookAhead = lookAhead;
_evaluate = evaluate;
}