当前位置: 首页>>代码示例>>C#>>正文


C# Predicate类代码示例

本文整理汇总了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);
        }
开发者ID:Joshua-Ferguson,项目名称:orleans,代码行数:7,代码来源:AssemblyLoaderPathNameCriterion.cs

示例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();
         }
     });
 }
开发者ID:wilson0x4d,项目名称:Mubox,代码行数:25,代码来源:VKBoard.xaml.cs

示例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);
                 }
             }
         }
     }
 }
开发者ID:julienblin,项目名称:NAntConsole,代码行数:32,代码来源:ZipHelper.cs

示例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);
        }
开发者ID:tuespetre,项目名称:HttpAbstractions,代码行数:37,代码来源:MapWhenExtensions.cs

示例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);
        }
开发者ID:szabototo89,项目名称:ms-frontend-development,代码行数:7,代码来源:ActionCommand.cs

示例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;
        }
开发者ID:ColinOrr,项目名称:echo,代码行数:12,代码来源:Response.cs

示例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();
        }
开发者ID:AlienEngineer,项目名称:ConcurrentReader,代码行数:32,代码来源:BlockingDataReader.cs

示例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;
 }
开发者ID:ProfoundDarkness,项目名称:MD2-Source,代码行数:7,代码来源:CremationTarget.cs

示例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;
        }
开发者ID:mstmdev,项目名称:Mstm.aspnetwebstack,代码行数:34,代码来源:TypeCacheUtil.cs

示例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;
    }
开发者ID:RainsSoft,项目名称:UJad-AI-VFS,代码行数:17,代码来源:DelegateCommand.cs

示例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;
        }
开发者ID:mparsin,项目名称:Elements,代码行数:26,代码来源:VisualTreeHelperEx.cs

示例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;
                }
            }
        }
开发者ID:kharlamov,项目名称:fubumvc,代码行数:36,代码来源:FubuModuleAttributePackageLoader.cs

示例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);
     }
 }
开发者ID:bangbang93,项目名称:sinablack,代码行数:29,代码来源:FlvParser.cs

示例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;
 }
开发者ID:selvendiranj,项目名称:compositewpf-copy,代码行数:12,代码来源:ViewsCollection.cs

示例15: Rule

 public Rule(Parser parser, RuleType ruleType, Predicate<Parser> lookAhead, RuleDelegate evaluate)
 {
     _parser = parser;
     _ruleType = ruleType;
     _lookAhead = lookAhead;
     _evaluate = evaluate;
 }
开发者ID:Turbo87,项目名称:DGrok,代码行数:7,代码来源:Rule.cs


注:本文中的Predicate类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。