本文整理汇总了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;
}
}
}
}
}
}
示例2: EnsureFieldCondition
private void EnsureFieldCondition(Predicate<int> condition)
{
lock (locker)
{
Assert.IsTrue(condition.Invoke(fieldToUpdate));
}
}
示例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;
}
示例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();
}
}
}
}
}
示例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);
}
示例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;
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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; }
}
示例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;
}
示例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;
}
示例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);
}
}
示例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();
}
示例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();
}