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


C# IEnumerable.Where方法代码示例

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


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

示例1: ASIC

        private  XElement ASIC(IEnumerable<XElement> rows) {
            bool hasASIC = rows.Where(x => x.Element("COMMODITYCLASS").Value == "ASIC").Any();
               if (hasASIC)
               {
                   XElement asic = new XElement("ASIC");
                   IEnumerable<string> orderkeys = rows.Where(x => x.Element("COMMODITYCLASS").Value == "ASIC").Select(x => x.Element("ORDERKEY").Value).Distinct();
                   foreach (string orderkey in orderkeys)
                   {
                       //表头/表体分组
                       XElement orderel = new XElement("ORDER");
                       orderel.Add(new XElement("ORDERKEY", orderkey));
                       string externorderkey = rows.Where(x =>
                           x.Element("ORDERKEY").Value == orderkey &&
                           x.Element("COMMODITYCLASS").Value == "ASIC").Select(x => x.Element("EXTERNORDERKEY").Value).First();
                       orderel.Add(new XElement("EXTERNORDERKEY", externorderkey));
                       string comcode = rows.Where(x =>
                           x.Element("ORDERKEY").Value == orderkey &&
                           x.Element("COMMODITYCLASS").Value == "ASIC").Select(x => x.Element("COMCODE").Value).First();
                       orderel.Add(new XElement("COMCODE", comcode));
                       XElement orderdetail = new XElement("ORDERDETAIL");
                       IEnumerable<XElement> detail = rows.Where(x =>
                           x.Element("ORDERKEY").Value == orderkey &&
                           x.Element("COMMODITYCLASS").Value == "ASIC").ToArray();
                       //orderdetail.Add(detail);
                       orderel.Add(detail);
                       asic.Add(orderel);

                   }
                   return asic;

               }
               else {
                   return null;
               }
        }
开发者ID:neozhu,项目名称:Kaifa.B2B.Solution,代码行数:35,代码来源:OrderShipmentGenerator.cs

示例2: AbilityAnalyzer

        private static void AbilityAnalyzer(ILogMetrics data, IEnumerable<LogEntry> log)
        {
            var abilityNames = log.Where(m => m.ability.name != "").Select(m => m.ability.name).Distinct();
            foreach (var name in abilityNames)
            {
                var metrics = new AbilityMetrics();
                var abilityLog = log.Where(m => m.ability.name == name);

                var damageLog = abilityLog.DamageEffects();
                var healingLog = abilityLog.HealingEffects();
                var threatLog = abilityLog.ThreatEffects();

                data.AbilityMetrics.Add(metrics);

                metrics.Name = name;
                metrics.Number = abilityLog.First().ability.number;
                metrics.Count = abilityLog.Count();
                
                metrics.MaximumDamage = damageLog.IfEmpty(0, l => l.Max(m => m.result.amount));
                metrics.MinimumDamage = damageLog.IfEmpty(0, l => l.Min(m => m.result.amount));
                metrics.AverageDamage = damageLog.IfEmpty(0, l => l.Average(m => m.result.amount));

                metrics.MaximumHealing = healingLog.IfEmpty(0, l => l.Max(m => m.result.amount));
                metrics.MinimumHealing = healingLog.IfEmpty(0, l => l.Min(m => m.result.amount));
                metrics.AverageHealing = healingLog.IfEmpty(0, l => l.Average(m => m.result.amount));

                metrics.MaximumThreat = threatLog.IfEmpty(0, l => l.Max(m => m.result.amount));
                metrics.MinimumThreat = threatLog.IfEmpty(0, l => l.Min(m => m.result.amount));
                metrics.AverageThreat = threatLog.IfEmpty(0, l => l.Average(m => m.result.amount));

                metrics.CountOfCriticals = abilityLog.Where(m => m.result.isCritical).Count();
            }
            data.AbilityMetrics = data.AbilityMetrics.OrderByDescending(m => m.Count).ThenBy(m => m.Name).ToList();
        }
开发者ID:trayburn,项目名称:SWTOR.Parser,代码行数:34,代码来源:CombatParser.cs

示例3: ClassTypeTree

        /// <summary>
        /// Initializes a new instance of the <see cref="ClassTypeTree"/> class.
        /// </summary>
        /// <param name="types">The types to build the tree out of.</param>
        public ClassTypeTree(IEnumerable<Type> types)
        {
            // ReSharper disable DoNotCallOverridableMethodsInConstructor

            var childList = new List<ClassTypeTree>();

            // Remove duplicates
            types = types.Where(x => x.IsClass).Distinct();

            // Grab the lowest-level types
            var baseTypes = types.Where(x => !types.Any(y => x != y && y.IsAssignableFrom(x)));

            // Grab the possible child types
            var remainingTypes = types.Except(baseTypes);
            foreach (var bt in baseTypes)
            {
                // Recursively build the tree
                childList.Add(CreateNode(this, bt, remainingTypes));
            }

            // Add the wildcard for the base level
            childList.Add(CreateNode(this, null, null));

            // Store the children
            _children = FinalizeChildren(childList);

            // ReSharper restore DoNotCallOverridableMethodsInConstructor
        }
开发者ID:mateuscezar,项目名称:netgore,代码行数:32,代码来源:ClassTypeTree.cs

示例4: SpecificationContainer

 protected SpecificationContainer(IEnumerable<Specification> specifications)
 {
   _totalSpecifications = specifications.Count();
   _passingSpecifications = specifications.Where(x => x.Status == Status.Passing).Count();
   _failingSpecifications = specifications.Where(x => x.Status == Status.Failing).Count();
   _notImplementedSpecifications = specifications.Where(x => x.Status == Status.NotImplemented).Count();
 }
开发者ID:jayhill,项目名称:machine.specifications,代码行数:7,代码来源:SpecificationContainer.cs

示例5: GetOrderedLanes

        private static IEnumerable<LaneModel> GetOrderedLanes(IEnumerable<LaneModel> laneStats)
        {
            var orderedLaneStats = new List<LaneModel>();

            Func<LaneModel, bool> backLogPred = x => x.ClassType == LaneClassType.Backlog && x.Relation != "child";
            Func<LaneModel, bool> activePred = x => x.ClassType == LaneClassType.Active;
            Func<LaneModel, bool> archivePred = x => x.ClassType == LaneClassType.Archive && x.Relation != "child";

            if (laneStats.Any(backLogPred))
            {
                orderedLaneStats.AddRange(laneStats.Where(backLogPred).OrderBy(x => x.Index));
            }

            if (laneStats.Any(activePred))
            {
                orderedLaneStats.AddRange(laneStats.Where(activePred).OrderBy(x => x.Index));
            }

            if (laneStats.Any(archivePred))
            {
                orderedLaneStats.AddRange(laneStats.Where(archivePred).OrderBy(x => x.Index));
            }

            return orderedLaneStats;
        }
开发者ID:clickless,项目名称:LeanKit.IntegrationService,代码行数:25,代码来源:HtmlHelpers.cs

示例6: CallInitMethods

        //public void CallInitMethods(IEnumerable<string> initMethodNames, IEnumerable<string> endMethodNames, Func<string, MethodInfo> getMethod)
        //{
        //    Dictionary<string, MethodInfo> initMethods = CreateDictionary(initMethodNames);
        //    Dictionary<string, MethodInfo> endMethods = CreateDictionary(endMethodNames);

        //    bool callInit = _callInit;

        //    //if (forceCallInit)
        //    //    callInit = true;

        //    // check if init methods or end methods change
        //    if (!callInit && (!MethodsEquals(_initMethods, initMethods) || !MethodsEquals(_endMethods, endMethods)))
        //        callInit = true;


        //    if (callInit)
        //    {
        //        CallEndMethods();

        //        GetMethods(initMethods, getMethod);
        //        GetMethods(endMethods, getMethod);
        //        _initMethods = initMethods;
        //        _endMethods = endMethods;
        //        CallMethods(_initMethods, init: true);
        //        _callInit = false;
        //    }
        //}

        // callInit
        public void CallInitMethods(IEnumerable<InitEndMethod> initMethods, IEnumerable<InitEndMethod> endMethods, bool callInitRunOnce, Func<string, MethodInfo> getMethod)
        {
            Dictionary<string, MethodInfo> initMethodsRunAlways = CreateDictionary(initMethods.Where(method => method.RunType == RunType.Always).Select(method => method.Name));
            Dictionary<string, MethodInfo> endMethodsRunAlways = CreateDictionary(endMethods.Where(method => method.RunType == RunType.Always).Select(method => method.Name));
            Dictionary<string, MethodInfo> initMethodsRunOnce = CreateDictionary(initMethods.Where(method => method.RunType == RunType.Once).Select(method => method.Name));
            Dictionary<string, MethodInfo> endMethodsRunOnce = CreateDictionary(endMethods.Where(method => method.RunType == RunType.Once).Select(method => method.Name));

            //bool callInit = _callInit;

            // check if init methods or end methods change
            if (!callInitRunOnce && (!MethodsEquals(_initMethodsRunOnce, initMethodsRunOnce) || !MethodsEquals(_endMethodsRunOnce, endMethodsRunOnce)))
                callInitRunOnce = true;

            if (callInitRunOnce)
                CallEndMethodsRunOnce();

            CallEndMethodsRunAlways();

            if (callInitRunOnce)
            {
                GetMethods(initMethodsRunOnce, getMethod);
                GetMethods(endMethodsRunOnce, getMethod);
                _initMethodsRunOnce = initMethodsRunOnce;
                _endMethodsRunOnce = endMethodsRunOnce;
                CallMethods(_initMethodsRunOnce, always: false, init: true);
                _callInitRunOnce = false;
            }

            GetMethods(initMethodsRunAlways, getMethod);
            GetMethods(endMethodsRunAlways, getMethod);
            _endMethodsRunAlways = endMethodsRunAlways;
            CallMethods(initMethodsRunAlways, always: true, init: true);
        }
开发者ID:labeuze,项目名称:source,代码行数:62,代码来源:RunSourceInitEndMethods_v1.cs

示例7: GenerateContent

        public StringBuilder GenerateContent(string requestPath, IEnumerable<IFileInfo> contents)
        {
            if (contents == null)
            {
                throw new ArgumentNullException("contents");
            }

            var builder = new StringBuilder();
            builder.AppendFormat("{0}\r\n", requestPath);
            builder.Append("\r\n");

            foreach (var subdir in contents.Where(info => info.IsDirectory))
            {
                builder.AppendFormat("{0}/\r\n", subdir.Name);
            }
            builder.Append("\r\n");

            foreach (var file in contents.Where(info => !info.IsDirectory))
            {
                builder.AppendFormat("{0}, {1}, {2}\r\n", file.Name, file.Length, file.LastModified);
            }
            builder.Append("\r\n");

            return builder;
        }
开发者ID:tkggand,项目名称:katana,代码行数:25,代码来源:PlainTextDirectoryFormatter.cs

示例8: Process

        public IEnumerable<IOperation> Process(IEnumerable<IOperation> operations)
        {
            var operation = operations.Where(x => x.GetRequestCodec() != null)
                                .OrderByDescending(x => x.GetRequestCodec()).FirstOrDefault()
                            ?? operations.Where(x => x.Inputs.AllReady())
                                   .OrderByDescending(x => x.Inputs.CountReady()).FirstOrDefault();
            if (operation == null)
            {
                Log.OperationNotFound();
                yield break;
            }

            Log.OperationFound(operation);

            if (operation.GetRequestCodec() != null)
            {
                var codecInstance = CreateMediaTypeReader(operation);

                var codecType = codecInstance.GetType();
                Log.CodecLoaded(codecType);

                if (codecType.Implements(typeof(IKeyedValuesMediaTypeReader<>)))
                    if (TryAssignKeyedValues(_request.Entity, codecInstance, codecType, operation))
                    {
                        yield return operation;
                        yield break;
                    }

                if (codecType.Implements<IMediaTypeReader>())
                    if (!TryReadPayloadAsObject(_request.Entity, (IMediaTypeReader)codecInstance, operation))
                        yield break;
            }
            yield return operation;
        }
开发者ID:dhootha,项目名称:openrasta-core,代码行数:34,代码来源:RequestEntityReaderHydrator.cs

示例9: PlaySounds

        public void PlaySounds(IEnumerable<ProjectStatus> currentBuildData)
        {
            var newlyBrokenBuilds =
                currentBuildData.Where(proj => proj.IsBroken)
                                .Intersect(_previousBuildData.Where(proj => !proj.IsBroken));

            if (newlyBrokenBuilds.Any())
            {
                _audioPlayer.Play(_brokenBuildSound);
                _audioPlayer.Say(_speechMaker.BuildIsBroken(newlyBrokenBuilds));
            }
            else
            {
                var newlyFixedBuilds =
                    currentBuildData.Where(proj => proj.IsSuccessful)
                                    .Intersect(_previousBuildData.Where(proj => !proj.IsSuccessful));

                if (newlyFixedBuilds.Any())
                {
                    _audioPlayer.Play(_fixedBuildSound);
                    _audioPlayer.Say(_speechMaker.BuildIsFixed(newlyFixedBuilds));
                }
            }

            _previousBuildData = currentBuildData;
        }
开发者ID:xerxesb,项目名称:cradiator,代码行数:26,代码来源:DiscJockey.cs

示例10: FilterMethodByParams

 /// <summary>
 /// Permet de filtrer sur les parametres d'une fonction pour les fonctions surchargées
 /// </summary>
 /// <param name="methods"></param>
 /// <param name="parameters"></param>
 /// <returns></returns>
 private static MethodInfo FilterMethodByParams(IEnumerable<MethodInfo> methods, IEnumerable<object> parameters)
 {
     if (parameters != null)
     {
         var paramsNull = parameters.Where(p => p.Equals(null));
         if (!paramsNull.Any())
         {
             IEnumerable<Type> types = parameters.Select(param => param.GetType());
             var methodsFiltered = methods.Where(m => m.GetParameters().Count() == parameters.Count());
             if (methodsFiltered.Any())
             {
                 foreach (var methodInfo in methodsFiltered)
                 {
                     if (types.SequenceEqual(methodInfo.GetParameters().Select(p => p.ParameterType).ToList()))
                     {
                         return methodInfo;
                     }
                 }
             }
         }
         else
         {
             var methodsFiltered = methods.Where(m => m.GetParameters().Count() == parameters.Count());
             if (methodsFiltered.Any())
             {
                 return methodsFiltered.First();
             }
         }
     }
     return null;
 }
开发者ID:ToliConsulting,项目名称:navegar,代码行数:37,代码来源:TypeExtensions.cs

示例11: PlayerDashBoardViewModel

        public PlayerDashBoardViewModel(IEnumerable<League> leagues, Season currentSeason, IEnumerable<PlayerPredictionSummary> predictions, IEnumerable<PlayerPredictionSummary> LastWeekPredictions, Player playerProfile, Week LastWeek, Boolean IsViewingMyOwnPage, IQueryable<Notification> repnotifications)
        {
            LeagueSelections = leagues.ToDictionary((x => x.Name), x => x.Id.ToString());
            CurrentSeasonText = string.Format("{0} - {1} to {2}", currentSeason.League.Name, currentSeason.SeasonStarts.ToLongDateString(), currentSeason.SeasonEnd.ToLongDateString());

            ThisWeek = currentSeason.GetCurrentWeekSeason();
            IsMyPage = IsViewingMyOwnPage;

            if (predictions != null)
            {
                PredictionsWithOutComes = predictions.Where(x => x.HasOutcome).OrderBy(y=>y.MatchDate);
                PredictionUpComingMatches = predictions.Where(x => !x.HasOutcome).OrderBy(y => y.MatchDate);
                ThisWeeksMotWId = ThisWeek != null && ThisWeek.MatchOfTheWeek != null ? ThisWeek.MatchOfTheWeek.Id : 0;
            }
            if (LastWeekPredictions != null)
            {
                PredictionsOfPreviousWeek = LastWeekPredictions.OrderBy(y => y.MatchDate);

                LastWeeksMotWId = LastWeek != null && LastWeek.MatchOfTheWeek != null ? LastWeek.MatchOfTheWeek.Id : 0;
            }

            //Build Players Table
            Points = currentSeason.Weeks.WeeksSoFar().Select(w => currentSeason.GetTotalPointsForAPlayersWeek(playerProfile, w)).ToList();
            WeekNames = currentSeason.Weeks.WeeksSoFar().Select(x => x.WeekStarts.Day.ordinalNum() + " " + x.WeekStarts.ToString("MMM")).ToArray();

            //set up notifications
            notifications = repnotifications.Take(3);

            AllPredictionsConfirmed = ThisWeek != null ? playerProfile.HasCompletedPredictions(ThisWeek) : true;
        }
开发者ID:elmo61,项目名称:BritBoxing,代码行数:30,代码来源:PlayerDashBoardViewModel.cs

示例12: BPLPlayerViewModel

        public BPLPlayerViewModel(IEnumerable<League> leagues, Season currentSeason, IEnumerable<PlayerPredictionSummary> predictions, IEnumerable<PlayerPredictionSummary> LastWeekPredictions, Player LoggedInPlayer, Week LastWeek)
        {
            LeagueSelections = leagues.ToDictionary((x => x.Name), x => x.Id.ToString());
            CurrentSeasonText = string.Format("{0} - {1} to {2}", currentSeason.League.Name, currentSeason.SeasonStarts.ToLongDateString(), currentSeason.SeasonEnd.ToLongDateString());

            ThisWeek = currentSeason.GetCurrentWeekSeason();

            if (predictions != null)
            {
                PredictionsWithOutComes = predictions.Where(x => x.HasOutcome).OrderBy(y=>y.MatchDate);
                PredictionUpComingMatches = predictions.Where(x => !x.HasOutcome).OrderBy(y => y.MatchDate);
                ThisWeeksMotWId = ThisWeek != null && ThisWeek.MatchOfTheWeek != null ? ThisWeek.MatchOfTheWeek.Id : 0;
            }
            if (LastWeekPredictions != null)
            {
                PredictionsOfPreviousWeek = LastWeekPredictions.OrderBy(y => y.MatchDate);

                LastWeeksMotWId = LastWeek != null && LastWeek.MatchOfTheWeek != null ? LastWeek.MatchOfTheWeek.Id : 0;
            }

            //Build Players Table
            Points = currentSeason.Weeks.WeeksSoFar().Select(w => currentSeason.GetTotalPointsForAPlayersWeek(LoggedInPlayer, w)).ToList();
            WeekNames = currentSeason.Weeks.WeeksSoFar().Select(x => x.WeekStarts.Day.ordinalNum() + " " + x.WeekStarts.ToString("MMM")).ToArray();

            AllPredictionsConfirmed = ThisWeek != null ? LoggedInPlayer.HasCompletedPredictions(ThisWeek) : true;
        }
开发者ID:elmo61,项目名称:BritBoxing,代码行数:26,代码来源:BPLPlayerViewModel.cs

示例13: Process

        public IEnumerable<IAsset> Process(IEnumerable<IAsset> assets)
        {
            var results = assets.Where(a => !a.IsProcessable).ToList();

            IEnumerable<IGrouping<IAssetKey, IAsset>> assetGroups = assets.Where(a => a.IsProcessable).GroupBy(asset => asset.Key);

            foreach (IGrouping<IAssetKey, IAsset> assetGroup in assetGroups) {
                if (assetGroup.Count() == 1) {
                    results.Add(assetGroup.Single());
                } else {

                    var combinedTextBuilder = new StringBuilder();
                    var associatedFilePaths = new List<string>();
                    foreach (IAsset asset in assetGroup.OrderByDescending(a => a.OnLayoutPage)) {
                        associatedFilePaths.AddRange(asset.Reader.AssociatedFilePaths);
                        combinedTextBuilder.AppendLine(asset.Reader.Content);
                    }

                    var newContent = combinedTextBuilder.ToString();

                    var newAsset = assetGroup.First();
                    newAsset.Reader = new MemoryAssetReader(associatedFilePaths, newContent);
                    results.Add(newAsset);
                }
            }

            return results;
        }
开发者ID:pombredanne,项目名称:LuckyAssetManager,代码行数:28,代码来源:CombineProcessor.cs

示例14: GetEffectViaFilter

        internal static EntityStoreSchemaFilterEffect GetEffectViaFilter(
            this EntityStoreSchemaFilterEntry entryToTest, IEnumerable<EntityStoreSchemaFilterEntry> filterEntries)
        {
            var effect = EntityStoreSchemaFilterEffect.Exclude;

            // Look for the all filter for specific type of object; this includes the 'All' types filter
            foreach (var entry in filterEntries.Where(e => e.Name == "%" && (e.Types & entryToTest.Types) == entryToTest.Types))
            {
                effect = entry.Effect;
                break;
            }

            // Look for the specific type of object
            foreach (var entry in filterEntries.Where(
                e =>
                e.Catalog.Equals(entryToTest.Catalog ?? String.Empty, StringComparison.CurrentCulture) &&
                e.Schema.Equals(entryToTest.Schema ?? String.Empty, StringComparison.CurrentCulture) &&
                e.Name.Equals(entryToTest.Name ?? String.Empty, StringComparison.CurrentCulture)))
            {
                effect = entry.Effect;
                break;
            }

            return effect;
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:25,代码来源:SchemaFilterEntryExtensions.cs

示例15: CreatePaymentButtons

        private IEnumerable<CommandButtonViewModel<PaymentType>> CreatePaymentButtons(IEnumerable<PaymentType> paymentTypes, ForeignCurrency foreignCurrency)
        {
            var result = new List<CommandButtonViewModel<PaymentType>>();
            if (_settleCommand != null)
            {
                result.Add(new CommandButtonViewModel<PaymentType>
                {
                    Caption = Resources.Settle,
                    Command = _settleCommand,
                });
            }

            var pts = foreignCurrency == null ? paymentTypes.Where(x => x.Account == null || x.Account.ForeignCurrencyId == 0) : paymentTypes.Where(x => x.Account != null && x.Account.ForeignCurrencyId == foreignCurrency.Id);
            result.AddRange(pts
                .OrderBy(x => x.SortOrder)
                .Select(x => new CommandButtonViewModel<PaymentType>
                {
                    Caption = x.Name.Replace(" ", "\r"),
                    Command = _makePaymentCommand,
                    Color = x.ButtonColor,
                    Parameter = x
                }));

            if (_closeCommand != null)
            {
                result.Add(new CommandButtonViewModel<PaymentType>
                {
                    Caption = Resources.Close,
                    Command = _closeCommand,
                    Color = "Red"
                });
            }
            return result;
        }
开发者ID:neapolis,项目名称:SambaPOS-3,代码行数:34,代码来源:PaymentButtonGroupViewModel.cs


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