當前位置: 首頁>>代碼示例>>C#>>正文


C# System.Collections.Generic.List.Where方法代碼示例

本文整理匯總了C#中System.Collections.Generic.System.Collections.Generic.List.Where方法的典型用法代碼示例。如果您正苦於以下問題:C# System.Collections.Generic.List.Where方法的具體用法?C# System.Collections.Generic.List.Where怎麽用?C# System.Collections.Generic.List.Where使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Collections.Generic.System.Collections.Generic.List的用法示例。


在下文中一共展示了System.Collections.Generic.List.Where方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ReturnOnlyRightElements

        // 20130513
        //internal ArrayList returnOnlyRightElements(
        internal static ArrayList ReturnOnlyRightElements(
            //AutomationElementCollection results,
            // 20130513
            HasTimeoutCmdletBase cmdlet,
            IEnumerable results,
            //System.Collections.Generic.IEnumerable<AutomationElement> results,
            string name,
            string automationId,
            string className,
            string textValue,
            string[] controlType,
            bool caseSensitive)
        {
            ArrayList resultCollection = new ArrayList();

            WildcardOptions options;
            if (caseSensitive) {
                options =
                    WildcardOptions.Compiled;
            } else {
                options =
                    WildcardOptions.IgnoreCase |
                    WildcardOptions.Compiled;
            }

            if (null == name || string.Empty == name || 0 == name.Length) { name = "*"; }
            if (null == automationId || string.Empty == automationId || 0 == automationId.Length) { automationId = "*"; }
            if (null == className || string.Empty == className || 0 == className.Length) { className = "*"; }
            if (null == textValue || string.Empty == textValue || 0 == textValue.Length) { textValue = "*"; }

            //Console.WriteLine("name = " + name);
            //Console.WriteLine("auId = " + automationId);
            //Console.WriteLine("class = " + className);
            //Console.WriteLine("value = " + textValue);

            WildcardPattern wildcardName =
                new WildcardPattern(name, options);
            WildcardPattern wildcardAutomationId =
                new WildcardPattern(automationId, options);
            WildcardPattern wildcardClass =
                new WildcardPattern(className, options);
            WildcardPattern wildcardValue =
                new WildcardPattern(textValue, options);
            // 20130513
            //this.WriteVerbose(this, "inside the returnOnlyRightElements method 20");
            cmdlet.WriteVerbose(cmdlet, "inside the returnOnlyRightElements method 20");
                System.Collections.Generic.List<AutomationElement> list =
                    new System.Collections.Generic.List<AutomationElement>();

                // 20130513
                foreach (AutomationElement elt in results) {

                    list.Add(elt);

                }
                //list.AddRange(results);
                //list.AddRange(results.AsQueryable());

            try {

                var query = list
            //                    .Where<AutomationElement>(item => wildcardName.IsMatch(item.Current.Name))
            //                    .Where<AutomationElement>(item => wildcardAutomationId.IsMatch(item.Current.AutomationId))
            //                    .Where<AutomationElement>(item => wildcardClass.IsMatch(item.Current.ClassName))
            //                    .Where<AutomationElement>(item =>
            //                                              item.GetSupportedPatterns().Contains(ValuePattern.Pattern) ?
            //                                              //(("*" != textValue) ? wildcardValue.IsMatch((item.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern).Current.Value) : false) :
            //                                              (("*" != textValue) ? (positiveMatch(item, wildcardValue, textValue)) : (negativeMatch(textValue))) :
            //                                              true
            //                                              )
                    .Where<AutomationElement>(
                        item => (wildcardName.IsMatch(item.Current.Name) &&
                                 wildcardAutomationId.IsMatch(item.Current.AutomationId) &&
                                 wildcardClass.IsMatch(item.Current.ClassName) &&
                                 // check whether a control has or hasn't ValuePattern
                                 (item.GetSupportedPatterns().Contains(ValuePattern.Pattern) ?
                                  // 20130513
                                  //testRealValueAndValueParameter(item, name, automationId, className, textValue, wildcardValue) :
                                  cmdlet.testRealValueAndValueParameter(item, name, automationId, className, textValue, wildcardValue) :
                                  // check whether the -Value parameter has or hasn't value
                                  ("*" == textValue ? true : false)
                                 )
                                )
                       )
                    .ToArray<AutomationElement>();

                // 20130513
                //this.WriteVerbose(
                //    this,
                cmdlet.WriteVerbose(
                        cmdlet,
                        "There are " +
                        query.Count().ToString() +
                        " elements");

                resultCollection.AddRange(query);

                // 20130513
//.........這裏部分代碼省略.........
開發者ID:krukovskiy,項目名稱:STUPS,代碼行數:101,代碼來源:HasTimeoutCmdletBase.cs


注:本文中的System.Collections.Generic.System.Collections.Generic.List.Where方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。