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


C# Predicate.Invoke方法代码示例

本文整理汇总了C#中Predicate.Invoke方法的典型用法代码示例。如果您正苦于以下问题:C# Predicate.Invoke方法的具体用法?C# Predicate.Invoke怎么用?C# Predicate.Invoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Predicate的用法示例。


在下文中一共展示了Predicate.Invoke方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RemoveUserFromRule

		public void RemoveUserFromRule(string providers, string path, string accountName)
		{
			var rulePredicate = new Predicate<ConfigurationElement>(x => { return x.Attributes["providers"].Value.Equals(providers) && x.Attributes["path"].Value.Equals(path); });
			//
			var userPredicate = new Predicate<ConfigurationElement>(x => { return x.Attributes["name"].Value.Equals(accountName); });
			//
			using (var srvman = new ServerManager())
			{
				var adminConfig = srvman.GetAdministrationConfiguration();
				//
				var delegationSection = adminConfig.GetSection("system.webServer/management/delegation");
				//
				var rulesCollection = delegationSection.GetCollection();
				// Update rule if exists
				foreach (var rule in rulesCollection)
				{
					if (rulePredicate.Invoke(rule) == true)
					{
						var permissions = rule.GetCollection("permissions");
						//
						foreach (var user in permissions)
						{
							if (userPredicate.Invoke(user))
							{
								permissions.Remove(user);
								//
								srvman.CommitChanges();
								//
								break;
							}
						}
					}
				}
			}
		}
开发者ID:jordan49,项目名称:websitepanel,代码行数:35,代码来源:DelegationRulesModuleService.cs

示例2: EnsureFieldCondition

 private void EnsureFieldCondition(Predicate<int> condition)
 {
     lock (locker)
     {
         Assert.IsTrue(condition.Invoke(fieldToUpdate));
     }
 }
开发者ID:spati2,项目名称:FSE-2012-SANDO,代码行数:7,代码来源:TimedProcessorTests.cs

示例3: GetClosestAncestor

        public SyntaxNode GetClosestAncestor(Predicate<SyntaxNode> condition)
        {
            SyntaxNode ancestor;

            // Iteratively get parent node until the node met with the given condition.
            for (ancestor = node; ancestor != null && !condition.Invoke(ancestor); ancestor = ancestor.Parent) ;
            return ancestor;
        }
开发者ID:nkcsgexi,项目名称:GhostFactor2,代码行数:8,代码来源:SyntaxNodeAnalyzer.cs

示例4: RestrictRuleToUser

		public void RestrictRuleToUser(string providers, string path, string accountName)
		{
			var rulePredicate = new Predicate<ConfigurationElement>(x => { return x.Attributes["providers"].Value.Equals(providers) && x.Attributes["path"].Value.Equals(path); });
			//
			var userPredicate = new Predicate<ConfigurationElement>(x => { return x.Attributes["name"].Value.Equals(accountName); });
			//
			using (var srvman = new ServerManager())
			{
				var adminConfig = srvman.GetAdministrationConfiguration();

                // return if system.webServer/management/delegation section is not exist in config file 
                if (!HasDelegationSection(adminConfig))
			        return;
				
                var delegationSection = adminConfig.GetSection("system.webServer/management/delegation");
				//
				var rulesCollection = delegationSection.GetCollection();
				// Update rule if exists
				foreach (var rule in rulesCollection)
				{
					if (rulePredicate.Invoke(rule) == true)
					{
						var permissions = rule.GetCollection("permissions");
						//
						var user = default(ConfigurationElement);
						//
						foreach (var item in permissions)
						{
							if (userPredicate.Invoke(item))
							{
								user = item;
								//
								break;
							}
						}
						//
						if (user == null)
						{
							user = permissions.CreateElement("user");
							//
							user.SetAttributeValue("name", accountName);
							user.SetAttributeValue("isRole", false);
							//
							permissions.Add(user);
						}
						//
						if (user != null)
						{
							user.SetAttributeValue("accessType", "Deny");
							//
							srvman.CommitChanges();
						}
					}
				}
			}
		}
开发者ID:lwhitelock,项目名称:Websitepanel,代码行数:56,代码来源:DelegationRulesModuleService.cs

示例5: test

 internal static void test(string input, Predicate<ParseTreeNode> condition = null)
 {
     var p = parse(input);
     if (condition != null)
     {
         Assert.IsTrue(condition.Invoke(p.SkipToRelevant()), "condition failed for input '{0}'", input);
     }
     // Also do a print test for every parse
     PrintTests.test(formula: input, parsed: p);
 }
开发者ID:codedecay,项目名称:XLParser,代码行数:10,代码来源:ParserTests.cs

示例6: MatchingNodes

 public static List<XmlNode> MatchingNodes(XmlDocument xmlDocument, string nodeTag, Predicate<XmlNode> predicate)
 {
     XmlNodeList nodes = xmlDocument.GetElementsByTagName(nodeTag);
     List<XmlNode> matchingNodes = new List<XmlNode>();
     foreach (XmlNode xmlNode in nodes)
     {
         if (predicate.Invoke(xmlNode))
             matchingNodes.Add(xmlNode);
     }
     return matchingNodes;
 }
开发者ID:tmandersson,项目名称:FastGTD,代码行数:11,代码来源:XML.cs

示例7: FindMessage

        public static void FindMessage(Predicate<Message> criteria, List<Message> result)
        {
            for (int i = 0; i < lastFrame_messages.Count; i++)
            {
                Message m = lastFrame_messages[i];
                if (criteria.Invoke(m))
                {
                    result.Add(m);

                }
            }
        }
开发者ID:patrykos91,项目名称:Laikos,代码行数:12,代码来源:EventManager.cs

示例8: CallingMethod

 public static Method CallingMethod(Predicate<MethodBase> predicate)
 {
     var stackTrace = new StackTrace();
     StackFrame[] frames = stackTrace.GetFrames();
     if (frames == null) return null;
     foreach (StackFrame stackFrame in frames)
     {
         MethodBase method = stackFrame.GetMethod();
         if (predicate.Invoke(method)) return new Method((MethodInfo) method);
     }
     return null;
 }
开发者ID:domik82,项目名称:bricks-toolkit,代码行数:12,代码来源:Method.cs

示例9: GetClassesForPredicate

 /// <summary>
 /// Returns all types in the given assembly satisfying the given predicate,
 /// </summary>
 private static List<Type> GetClassesForPredicate(Assembly assembly, Predicate<Type> predicate)
 {
     List<Type> result = new List<Type>();
     foreach (Type t in assembly.GetTypes())
     {
         if (predicate.Invoke(t))
         {
             result.Add(t);
         }
     }
     return result;
 }
开发者ID:nickgirardo,项目名称:KADAPT,代码行数:15,代码来源:ReflectionUtil.cs

示例10: ContainsSequence

 public static int ContainsSequence(byte[] data, ref int i, Predicate<byte> p)
 {
     try
     {
         int count = 0;
         while (p.Invoke(data[i--]))
         {
             ++count;
         }
         ++i;
         return count;
     }
     catch { return 0; }
 }
开发者ID:PowerOfDark,项目名称:LoLPatchResolver,代码行数:14,代码来源:Utils.cs

示例11: EnumWindows

 public static IEnumerable<IWinApiWindow> EnumWindows(Predicate<IWinApiWindow> condition = null)
 {
     var windowsList = new List<IWinApiWindow>();
     EnumWindowsProc windowEnumDelegate = (wnd, param) =>
     {
         var window = new WinApiWindow(wnd);
         if (condition == null || condition.Invoke(window))
         {
             windowsList.Add(window);
         }
         return true;
     };
     User32.EnumWindows(windowEnumDelegate, IntPtr.Zero);
     return windowsList;
 }
开发者ID:kavengagne,项目名称:WinApiWrapper,代码行数:15,代码来源:WinApiWindow.Static.cs

示例12: GetCurrentFilePathWithSerialNo

		public static string GetCurrentFilePathWithSerialNo(string filePath, Predicate<string> predicate)
		{
			string filePathOfCurrent = filePath;
			string filePathOfMaxSerialNo = GetFilePathOfMaxSerialNo(filePath);

			if(!string.IsNullOrEmpty(filePathOfMaxSerialNo))
				filePathOfCurrent = filePathOfMaxSerialNo;

			if(predicate.Invoke(filePathOfCurrent))
				filePath = GetFilePathOfNextSerialNo(filePath);
			else
				filePath = filePathOfCurrent;

			return filePath;
		}
开发者ID:Flagwind,项目名称:Zongsoft.CoreLibrary,代码行数:15,代码来源:PathUtility.cs

示例13: WaitUntil

 protected void WaitUntil(Predicate<string> breakWhen, Func<string> evaluation, int timeout = 60)
 {
     for (int second = 0; ; second++)
     {
         if (second >= timeout)
             throw new TimeoutException();
         try
         {
             if (breakWhen.Invoke(evaluation()))
                 break;
         }
         catch (Exception)
         {
         }
         System.Threading.Thread.Sleep(1000);
     }
 }
开发者ID:dburriss,项目名称:UiMatic,代码行数:17,代码来源:ViewContainer.cs

示例14: SearchForFiles

        private static void SearchForFiles(string path, Predicate<FileInfo> condition)
        {
            List<MyFileInfo> files = new List<MyFileInfo>();
             foreach (FileInfo item in new DirectoryInfo(path).GetFiles())
             {
                 if(condition.Invoke(item))
                 {
                     files.Add(new MyFileInfo(item.Name) { Length = item.Length, CreationTime = item.CreationTime });
                 }
             }

             foreach (MyFileInfo item in files.OrderBy<MyFileInfo, long>((myfi) => (-myfi.Length)))
             {
                 Console.WriteLine(item);
             }

             //Console.WriteLine("Total size in bytes: {0}", files.TotalSize().ToString("N0"));
             Console.WriteLine("Total size in bytes of top two large files: {0}", files.OrderByDescending(fi => fi.Length).Take(2).Sum(fi => fi.Length).ToString("N0"));
             Console.ReadLine();
        }
开发者ID:naynishchaughule,项目名称:CSharp,代码行数:20,代码来源:RunTest.cs

示例15: RemoveRefactoringWarnings

        public void RemoveRefactoringWarnings(Predicate<IRefactoringWarningMessage> removingMessagesConditions)
        {
            var indexes = new List<int>();

            // For all the messages currently in the list.
            foreach (var inListMessage in messagesInListView)
            {
                // If the current message met with the given removing message condition.
                // Add the index of this message to indexes.
                if(removingMessagesConditions.Invoke(inListMessage))
                {
                    indexes.Add(messagesInListView.IndexOf(inListMessage));
                }
            }

            // Remove all messages as well as item in the list view.
            foreach (int i in indexes)
            {
                messagesInListView.RemoveAt(i);
                refactoringWarningsListView.Items.RemoveAt(i);
            }
            refactoringWarningsListView.Invalidate();
        }
开发者ID:nkcsgexi,项目名称:GhostFactor2,代码行数:23,代码来源:RefactoringWariningsForm.cs


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