/// <summary> /// 插入菜单项 /// </summary> /// <param name="text">菜单项</param> /// <param name="method">菜单响应方法</param> /// <param name="priority">优先级</param> /// <param name="condition">条件委托</param> /// <param name="obj"></param> public void InsertItem(string text, Delegate method, int priority, ConditionDelegate condition, System.Object obj) { if (method == null) { return; } int parameterslen = method.Method.GetParameters().Length; if (parameterslen > 1) { return; } if (parameterslen == 1 && obj == null) { return; } if (parameterslen == 0 && obj != null) { return; } if (string.IsNullOrEmpty(text)) { return; } if (m_Root == null) { m_Root = new ToolBarTreeNode("", 0); } m_Root.InsertNode(text, method.Method, method.Target, condition, obj, priority); }
public Teacher[] Find(ConditionDelegate condition) { int count = 0; foreach (var teacher in Teachers) { if (condition(teacher)) { count++; } } if (count == 0) { return(null); } Teacher[] foundTeachers = new Teacher[count]; int i = 0; foreach (var teacher in Teachers) { if (condition(teacher)) { foundTeachers[i++] = teacher; } } return(foundTeachers); }
public Student[] Find(ConditionDelegate condition) { int count = 0; foreach (var student in Students) { if (condition(student)) { count++; } } if (count == 0) { return(null); } Student[] foundStudents = new Student[count]; int i = 0; foreach (var student in Students) { if (condition(student)) { foundStudents[i++] = student; } } return(foundStudents); }
private void AddNode(string nodeText, string lasttext, int priority, MethodInfo method, System.Object target, ConditionDelegate condition, System.Object argobj, bool hasChild) { ToolBarTreeNode node = this.m_NodeList.Find(n => n.m_Text == nodeText); if (hasChild) { if (node == null) { node = new ToolBarTreeNode(nodeText, priority); node.InsertNode(lasttext, method, target, condition, argobj, priority); this.m_NodeList.Add(node); } else { node.InsertNode(lasttext, method, target, condition, argobj, priority); } } else { if (node == null) { node = new ToolBarTreeNode(nodeText, priority); node.CombineMethod(method, target, condition, argobj); this.m_NodeList.Add(node); } } }
private void IteratePath(string path, ConditionDelegate condition) { var dirInfo = new DirectoryInfo(path); var dirList = dirInfo.EnumerateDirectories(); var fileList = dirInfo.EnumerateFiles(); foreach (var item in dirList) { if (!item.Name.StartsWith(".")) { IteratePath(item.FullName, condition); } } foreach (var item in fileList) { if (condition(item)) { _fileList.Add(new FileSelection { FileName = item.Name, FilePath = GetPathOnly(item.FullName, item.Name.Length) }); } } }
/// <summary> /// Creates a new instance arounda <see cref="ConditionDelegate"/> /// </summary> /// <param name="condition"> /// <see cref="ConditionDelegate"/> to attach. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="condition"/> is a null reference. /// </exception> public ConditionDelegatePredicate(ConditionDelegate condition) { if (condition == null) { throw new ArgumentNullException("condition"); } this.condition = condition; }
/// <summary> /// Initializes a new instance of the <see cref="CC"/> class. /// </summary> /// <param name="ChampName">Name of the champ.</param> /// <param name="Slot">The slot.</param> /// <param name="Range">The range.</param> /// <param name="RangeType">Type of the range.</param> /// <param name="Type">The type.</param> /// <param name="d">The d.</param> public CC(string ChampName, SpellSlot Slot, float Range, CCRange RangeType, CCType Type, ConditionDelegate d) { this.ChampName = ChampName; this.Slot = Slot; this.Range = Range; this.RangeType = RangeType; this.Type = Type; this.NecessaryCondition = d; }
/// <summary> /// Initializes a new instance of the <see cref="CC" /> class. /// </summary> /// <param name="ChampName">Name of the champ.</param> /// <param name="Slot">The slot.</param> /// <param name="Range">The range.</param> /// <param name="RangeType">Type of the range.</param> /// <param name="Type">The type.</param> /// <param name="d">The d.</param> public CC(string ChampName, SpellSlot Slot, float Range, CCRange RangeType, CCType Type, ConditionDelegate d) { this.ChampName = ChampName; this.Slot = Slot; this.Range = Range; this.RangeType = RangeType; this.Type = Type; NecessaryCondition = d; }
private static void SumCompare(List<int> list, ConditionDelegate conditionDelegate) { Console.WriteLine(Sum(list, conditionDelegate)); list.Sort(); Console.WriteLine("Sorting Done!"); Console.WriteLine(Sum(list, conditionDelegate)); }
/// <summary> /// Creates a new instance of the <see cref="CC_Condition"/> class /// </summary> /// <param name="condition">The if condition</param> /// <param name="ifCommands">The commands for when the if condition is true</param> public CC_Condition(ConditionDelegate condition, params IConversionCommand[] ifCommands) { if (condition == null || ifCommands == null) { throw new ArgumentNullException(); } Condition = condition; IfCommands = ifCommands; }
public IEnumerable <int> GetNumbers(IEnumerable <int> numbers, ConditionDelegate condition) { foreach (var number in numbers) { if (condition(number)) { yield return(number); } } }
private static int Sum(List<int> list, ConditionDelegate Func) { int sum = 0; DateTime start = DateTime.Now; foreach (var i in list) { sum += Func(i); } Console.WriteLine(Func.Method.Name + " time: " + (DateTime.Now - start).Milliseconds); return sum; }
/// <summary> /// Creates a new instance of the <see cref="CC_Condition"/> class /// </summary> /// <param name="condition">The if condition</param> /// <param name="ifCommand">The command for when the if condition is true</param> /// <param name="elseCommand">The command for when the if condition is false</param> public CC_Condition(ConditionDelegate condition, IConversionCommand ifCommand, IConversionCommand elseCommand) { if (condition == null || ifCommand == null || elseCommand == null) { throw new ArgumentNullException(); } Condition = condition; IfCommands = new IConversionCommand[] { ifCommand }; ElseCommands = new IConversionCommand[] { elseCommand }; }
public ConversationSentence.OnConditionDelegate NewCondition(ConditionDelegate action) { if (null != action) { return(new ConversationSentence.OnConditionDelegate(action)); } else { return(null); } }
public static IEnumerable <T> GetElementsByCondition <T>(this IEnumerable <T> array, ConditionDelegate <T> predicate) { foreach (T item in array) { if (predicate(item)) { yield return(item); } } }
/// <summary> /// Try Sleeps until the timeout is reached, or the condition delegate returns true. No exception will be thrown. /// polling interval of 500 ms. /// </summary> /// <param name="timeout">The timeout time in seconds</param> /// <param name="condition">a function that returns boolean. This code will be run until it returns true or the tiemout is reached</param> /// <returns>True if condition meet.</returns> public static bool TryWait(int timeout, ConditionDelegate condition) { try { Wait(timeout, 500, String.Empty, condition); return true; } catch (TimeoutException) { return false; } }
public List <StudentUser> GetDataByCondition(List <StudentUser> source, ConditionDelegate mehtod) { var list = source; List <StudentUser> result = new List <StudentUser>(); foreach (StudentUser su in list) { //调用委托 执行 if (mehtod.Invoke(su)) { result.Add(su); } } return(result); }
public void OutPut() { //调用有参数有返回值的写法 ConditionDelegate method = new ConditionDelegate(Condition1); List <StudentUser> result = GetDataByCondition(this.GetStudentUserList(), method); ConditionDelegate method2 = new ConditionDelegate(Condition2); List <StudentUser> result2 = GetDataByCondition(this.GetStudentUserList(), method2); //调用无参无返回值的写法 NotReturnData method3 = new NotReturnData(DoNothing); method3.Invoke(); method3(); this.DoNothing(); method3 += new NotReturnData(DoNothing2); }
/// <summary> /// Wait until the timeout is reached, or the condition delegate returns true. Throw exception on timeout. /// </summary> /// <param name="timeout">The timeout time in seconds</param> /// <param name="interval">time between polls in Milliseconds</param> /// <param name="timeoutMessage">Message for TimeOutException</param> /// <param name="condition">a function that returns boolean. This code will be run until it returns true or the tiemout is reached</param> /// <exception cref="TimeoutException">When timeout is reached.</exception> public static void Wait(int timeout, int interval, string timeoutMessage, ConditionDelegate condition) { DateTime startTime = System.DateTime.Now; DateTime endTime = DateTime.Now.AddSeconds(timeout); while (DateTime.Now.CompareTo(endTime) < 0) { try { if (condition()) { return; } } catch (Exception e) { } System.Threading.Thread.Sleep(interval); } throw new TimeoutException(timeoutMessage); }
/// <summary> /// 方法合并 /// </summary> /// <param name="method"></param> /// <param name="target"></param> /// <param name="condition"></param> /// <param name="argobj"></param> private void CombineMethod(MethodInfo method, System.Object target, ConditionDelegate condition, System.Object argobj) { m_ArgObj = argobj; if (m_ArgObj != null) { m_Condition = condition; } else { m_Condition = null; } if (m_Action == null) { if (m_ArgObj == null) { m_Action = Delegate.CreateDelegate(typeof(System.Action), target, method); } else { m_Action = Delegate.CreateDelegate(typeof(System.Action <System.Object>), target, method); } } }
public DialogueCreator Condition(ConditionDelegate condition) { this.condition = condition; return(this); }
/// <summary> /// Sleeps until the timeout is reached, or the condition delegate returns true. /// polling interval of 500 ms. /// </summary> /// <param name="timeout">The timeout time in seconds</param> /// <param name="timeoutMessage">Message for TimeOutException</param> /// <param name="condition">a function that returns boolean. This code will be run until it returns true or the tiemout is reached</param> public static void Wait(int timeout, string timeoutMessage, ConditionDelegate condition) { Wait(timeout, 500, timeoutMessage, condition); }
public Action(ConditionDelegate CanActivate, ActivateDelegate Activate, float EnergyCost) { this.CanActivate = CanActivate; this.Activate = Activate; this.EnergyCost = EnergyCost; }
/// <summary> /// Instantiates watch decorator with a given condition /// </summary> /// <param name="condition">The condition.</param> /// <param name="node">The node.</param> public Watch(ConditionDelegate <E> condition, Node <E> node) : base(node) { this.condition = condition; }
public void WaitForCondition(ConditionDelegate predicate,string param) { for (int c = 0; c < 10; ++c) { this.GetEval("window.location.href"); if (!predicate(param)) { break; } } Debug.Assert(!predicate(param)); }
public void OpenConnection(ConditionDelegate condition) { OpenConnection(condition()); }
public void CloseConnection(ConditionDelegate condition) { CloseConnection(condition()); }
public DelegateCondition(ConditionDelegate condition) { _condition = condition; }
/// <summary> /// Instantiates condition task with a given condition delegate method. /// </summary> /// <param name="condition">Condition method.</param> public DelegateCondition(ConditionDelegate condition, bool isInstant) : base(isInstant) { _condition = condition; }
/// <summary> /// Creates a <see cref="ConditionDelegatePredicate"/> around /// <paramref name="condition"/> /// </summary> /// <param name="condition"> /// condition to wrap</param> /// <returns> /// A <see cref="ConditionDelegatePredicate"/> /// </returns> public static ConditionDelegatePredicate If(ConditionDelegate condition) { return new ConditionDelegatePredicate(condition); }
public Action() { this.CanActivate = null; this.Activate = null; this.EnergyCost = 0; }
public ConversationSentence.OnConditionDelegate Condition(ConditionDelegate action) { return(new ConversationSentence.OnConditionDelegate(action)); }
public ConditionNode(ConditionDelegate dlg) { _Condition = dlg; }
public void BeginTransaction(ConditionDelegate condition) { BeginTransaction(condition()); }
/// <summary> /// Instantiates condition task with a given condition delegate method. /// </summary> /// <param name="entity">Entity used in execution.</param> /// <param name="condition">Condition method.</param> public ConditionTask(ConditionDelegate <E> condition) : base() { this.condition = condition; }
public void CommitTransaction(ConditionDelegate condition) { CommitTransaction(condition()); }
public WireCondition(ConditionType type, string text, Colour colour, ConditionDelegate conditionDelegate) : base(type.Key, text, conditionDelegate) { this.Type = type; this.Colour = colour; }
public void RollbackTransaction(ConditionDelegate condition) { RollbackTransaction(condition()); }
public WatchTask(ConditionDelegate <E> condition, Node <E> node, E entity) : base(node, entity) { this.condition = condition; }
/// <summary> /// Creates a <see cref="ConditionDelegatePredicate"/> around /// <paramref name="condition"/> /// </summary> /// <param name="condition"> /// condition to wrap</param> /// <returns> /// A <see cref="ConditionDelegatePredicate"/> /// </returns> public static ConditionDelegatePredicate If(ConditionDelegate condition) { return(new ConditionDelegatePredicate(condition)); }
/// <summary> /// Creates a new instance arounda <see cref="ConditionDelegate"/> /// </summary> /// <param name="condition"> /// <see cref="ConditionDelegate"/> to attach. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="condition"/> is a null reference. /// </exception> public ConditionDelegatePredicate(ConditionDelegate condition) { if (condition==null) throw new ArgumentNullException("condition"); this.condition = condition; }
/// <summary> /// Creates a conditional rule with "if" rule and "else" rule. /// </summary> /// <param name="cond"> /// Condition expression /// </param> /// <param name="rule"> /// <see cref="IRule"/> to execute if condition is true. /// </param> /// <returns> /// A <see cref="ConditionalRule"/> implementing condition rule execution. /// </returns> public static ConditionalRule If(ConditionDelegate cond, IRule rule) { return new ConditionalRule(Predicates.If(cond),rule); }