示例#1
0
    /// <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);
    }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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);
                }
            }
        }
示例#5
0
        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;
 }
示例#7
0
文件: CC.cs 项目: luizssn/LeagueSharp
 /// <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;
 }
示例#8
0
文件: CC.cs 项目: Musee30/Elobuddyy
 /// <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;
 }
示例#9
0
        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));
        }
示例#10
0
        /// <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;
        }
示例#11
0
 public IEnumerable <int> GetNumbers(IEnumerable <int> numbers, ConditionDelegate condition)
 {
     foreach (var number in numbers)
     {
         if (condition(number))
         {
             yield return(number);
         }
     }
 }
示例#12
0
 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;
 }
示例#13
0
        /// <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 };
        }
示例#14
0
 public ConversationSentence.OnConditionDelegate NewCondition(ConditionDelegate action)
 {
     if (null != action)
     {
         return(new ConversationSentence.OnConditionDelegate(action));
     }
     else
     {
         return(null);
     }
 }
示例#15
0
 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;
     }
 }
示例#17
0
        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);
        }
示例#18
0
        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);
        }
示例#20
0
 /// <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);
         }
     }
 }
示例#21
0
 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);
 }
示例#23
0
 public Action(ConditionDelegate CanActivate, ActivateDelegate Activate, float EnergyCost)
 {
     this.CanActivate = CanActivate;
     this.Activate    = Activate;
     this.EnergyCost  = EnergyCost;
 }
示例#24
0
 /// <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;
 }
示例#25
0
        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));
        }
示例#26
0
 public void OpenConnection(ConditionDelegate condition)
 {
     OpenConnection(condition());
 }
示例#27
0
 public void CloseConnection(ConditionDelegate condition)
 {
     CloseConnection(condition());
 }
示例#28
0
 public DelegateCondition(ConditionDelegate condition)
 {
     _condition = condition;
 }
示例#29
0
 /// <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;
 }
示例#30
0
 /// <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);
 }
示例#31
0
 public Action()
 {
     this.CanActivate = null;
     this.Activate    = null;
     this.EnergyCost  = 0;
 }
示例#32
0
 public ConversationSentence.OnConditionDelegate Condition(ConditionDelegate action)
 {
     return(new ConversationSentence.OnConditionDelegate(action));
 }
示例#33
0
 public ConditionNode(ConditionDelegate dlg)
 {
     _Condition = dlg;
 }
示例#34
0
 public void BeginTransaction(ConditionDelegate condition)
 {
     BeginTransaction(condition());
 }
示例#35
0
 /// <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;
 }
示例#36
0
 public void CommitTransaction(ConditionDelegate condition)
 {
     CommitTransaction(condition());
 }
示例#37
0
 public WireCondition(ConditionType type, string text, Colour colour, ConditionDelegate conditionDelegate) : base(type.Key, text, conditionDelegate)
 {
     this.Type   = type;
     this.Colour = colour;
 }
示例#38
0
 public void RollbackTransaction(ConditionDelegate condition)
 {
     RollbackTransaction(condition());
 }
示例#39
0
 public WatchTask(ConditionDelegate <E> condition, Node <E> node, E entity)
     : base(node, entity)
 {
     this.condition = condition;
 }
示例#40
0
 /// <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;
 }
示例#42
0
 /// <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);
 }