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


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

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


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

示例1: BuildFilter

		private ElementFilter<ClientCompanyColumnName, ClientCompany, ClientCompaniesListFilter> BuildFilter(ClientCompaniesListFilter filter)
		{
			var companyActiveStatus = ClientCompanyStatus.Active.ToString();
			var companyInactiveStatus = ClientCompanyStatus.Inactive.ToString();

			IEnumerable<string> filterStatuses = new[] { companyActiveStatus, companyInactiveStatus };
			if (filter.FilterByActiveStatus || filter.FilterByInactiveStatus)
			{
				if (!filter.FilterByActiveStatus)
				{
					filterStatuses = filterStatuses.Where(e => e != companyActiveStatus);
				}

				if (!filter.FilterByInactiveStatus)
				{
					filterStatuses = filterStatuses.Where(e => e != companyInactiveStatus);
				}
			}

			return ShorFilter.AddFilter<ClientCompanyColumnName, ClientCompany, ClientCompaniesListFilter>(f => !string.IsNullOrWhiteSpace(f.CompanyName), c => c.CompanyName.ToUpper().Contains(filter.CompanyName.ToUpper())).
					AddFilter(f => !string.IsNullOrWhiteSpace(f.CompanyId), c => c.CompanyId.ToUpper().Contains(filter.CompanyId.ToUpper())).
					AddFilter(f => true, c => filterStatuses.Contains(c.StatusId)).
					AddFilter(f => filter.IsWholesaleChannel, c => c.Profile.IsWholesale).
					AddFilter(f => filter.IsLender, c => c.Profile.IsLender).
					AddOrders(ClientCompanyColumnName.CompanyNameOrder, c => c.CompanyName).
					AddOrders(ClientCompanyColumnName.CompanyIdOrder, c => c.CompanyId).
					AddOrders(ClientCompanyColumnName.Status, c => c.StatusId);
		}
开发者ID:evkap,项目名称:DVS,代码行数:28,代码来源:ClientCompaniesListService.cs

示例2: GetWardSlot

 public static InventorySlot GetWardSlot()
 {
     var wardIds = new[] { 2049, 2045, 2301, 2302, 2303, 3711, 1408, 1409, 1410, 1411, 3932, 3340, 2043 };
     return
         wardIds.Where(Items.CanUseItem)
             .Select(i => Program.Player.InventoryItems.First(slot => slot.Id == (ItemId)i))
             .FirstOrDefault();
 }
开发者ID:Inuyalx,项目名称:LeagueSharp,代码行数:8,代码来源:Common.cs

示例3: AsCached_CachesScalarData

        public void AsCached_CachesScalarData()
        {
            var data = new[] { new { Te2st = "value" } }.ToList();
            var query = data.Where(item => item.Te2st == "value").AsQueryable().AsCached();

            query.Count();

            data.Clear();

            Assert.AreEqual(1, query.Count());
        }
开发者ID:david0718,项目名称:LinqCache,代码行数:11,代码来源:QueryableExtentionTest.cs

示例4: AsCached_NotifysInvalidatonAfterGet

        public void AsCached_NotifysInvalidatonAfterGet()
        {
            var invalidatorMock = new Mock<Invalidator>();

            var data = new[] { new { Test = "value" } }.ToList();
            var query = data.Where(item => item.Test == "value").AsQueryable();

            query.AsCached().ToArray();
            query.AsCached(invalidatorMock.Object).ToArray();

            invalidatorMock.Verify(mock => mock.OnCacheHit(It.IsAny<Container>(), It.IsAny<IQueryable>(), It.IsAny<string>(), It.IsAny<object>()), Times.Once);
        }
开发者ID:david0718,项目名称:LinqCache,代码行数:12,代码来源:QueryableExtentionTest.cs

示例5: CompileQuerys

        public static MiningQuery CompileQuerys(string question)
        {
            var scopequery = default(MiningQuery);

            var querys = new Dictionary<string, IEnumerable<string>>();
            var expression = string.Empty;
            var match = default(Match);

            question = question?.ToLower();

            //  Welche Informationsobjekte sollen gefunden werden?
            var scopes = new[]
            {
                "rezept"
            };
            var contextscopes = scopes.Where(scope => question.Contains(scope)).Concat(question.Split(' ').First().GetPluralSynonyms());
            if (contextscopes.Any())
            {
                scopequery = new MiningQuery {
                    Target = MiningConstants.PropertyTag,
                    Expressions = contextscopes
                };

                //  Kontext = Rezept
                if(contextscopes.Any(scope => scope == "rezept"))
                {
                    var parameter = default(string);

                    //  Suchfaktor "Zutat"
                    expression = "mit.*";
                    match = Regex.Match(question, expression);
                    parameter = match != null && match.Success ? Regex.Replace(match.Value, "mit ", string.Empty) : parameter;

                    var zutaten = Regex.Split(parameter, "(und|oder|,)").Where(token => !Regex.IsMatch(token, "(und|oder|,)")).Select(token => token.Trim());
                    if(zutaten != null)
                    {
                        foreach(var zutat in zutaten)
                        {
                            var synonyms = zutat.GetPluralSynonyms();

                            var q = querys.ContainsKey("zutat") ? querys["zutat"] : new List<string>();
                            q = q.Concat(synonyms.Select(synonym => $".*?{synonym}.*?").Distinct());
                            querys["zutat"] = q;
                        }
                    }
                }
            }

            return scopequery;
        }
开发者ID:LegendOfGIT,项目名称:ButlerFramework,代码行数:50,代码来源:MiningCompiler.cs

示例6: AllBut

        public static IEnumerable<string> AllBut(params string[] exclude)
        {
            var names = new []
                            {
                                ProductName.AgedBrie,
                                ProductName.ConjuredManaCake,
                                ProductName.DexterityVest,
                                ProductName.MongooseElixir,
                                ProductName.BackStagePasses.Tafkal80Etc,
                                ProductName.Sulfuras.HandOfRagnaros
                            };

            return names.Where(x => exclude.All(y => y != x));
        }
开发者ID:clinington,项目名称:GildedRoseKata,代码行数:14,代码来源:ProductNameExtensions.cs

示例7: DoIt

        public void DoIt()
        {
            // Ex. 1
            {
                var ints = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
                var superbClasses = new List<SuperbClass>();

                for (var i = 0; i < ints.Length; i++)
                {
                    if (ints[i] % 2 == 0)
                    {
                        var superbClass = new SuperbClass { SuperbInt = ints[i] };
                        superbClasses.Add(superbClass);
                    }
                }

                var superbLinqClasses =
                    ints
                        .Where(i => i % 2 == 0)
                        .Select(i => new SuperbClass { SuperbInt = i });
            }

            // Ex. 2
            {
                var ints = new[] {1, 2, 3, 4, 5, 6, 7, 8, 9};
                var skip = true;
                var list = new List<int>();

                for (var i = 0; i < ints.Length; i++)
                {
                    if (ints[i]%3 == 0)
                    {
                        if (skip)
                        {
                            skip = false;
                            continue;
                        }

                        if (list.Count > 1)
                            break;

                        list.Add(ints[i]);
                    }
                }

                var myLinqList = ints.Where(i => i%3 == 0).Skip(1).Take(2);
            }
        }
开发者ID:Dorrro,项目名称:linq-pres,代码行数:48,代码来源:LinqExamples.cs

示例8: GetAreaType

        private string GetAreaType(string result)
        {
            var descriptionIndex = result.IndexOf('(');
            var contentsIndex = result.IndexOf('[');
            var dimensionsIndex = result.IndexOf('{');
            var indices = new[] { descriptionIndex, contentsIndex, dimensionsIndex };
            var validIndices = indices.Where(i => i >= 0);

            if (validIndices.Any() == false)
                return result;

            var firstIndex = validIndices.Min();
            var areaType = result.Substring(0, firstIndex);

            return areaType;
        }
开发者ID:DnDGen,项目名称:DungeonGen,代码行数:16,代码来源:AreaPercentileSelector.cs

示例9: GetProducts

        public IList<Product> GetProducts()
        {
            var products = new[]
                               {
                                   new Product {Id = 1, Name = "Apples"},
                                   new Product {Id = 2, Name = "Oranges"},
                                   new Product {Id = 3, Name = "Bananas"},
                                   new Product {Id = 4, Name = "Pineapples"},
                                   new Product {Id = 5, Name = "Puppies"},
                                   new Product {Id = 6, Name = "Mongoose"},
                                   new Product {Id = 7, Name = "Ponies"},
                                   new Product {Id = 8, Name = "Monkeys"}
                               };

            return products.Where(prod => !HideProductIds.Contains(prod.Id)).ToList();
        }
开发者ID:Eilon,项目名称:spark,代码行数:16,代码来源:SampleRepository.cs

示例10: NeighbourCells

        public IEnumerable<Cell> NeighbourCells(int width, int height)
        {
            var cells = new[]
                            {
                                new Cell(X - 1, Y - 1),
                                new Cell(X - 1, Y),
                                new Cell(X - 1, Y + 1),
                                new Cell(X, Y - 1),
                                new Cell(X, Y + 1),
                                new Cell(X + 1, Y - 1),
                                new Cell(X + 1, Y),
                                new Cell(X + 1, Y + 1),
                            };

            return cells.Where(c =>
                               c.X >= 0 && c.X < width &&
                               c.Y >= 0 && c.Y < height);
        }
开发者ID:Morriphi,项目名称:GameOfLife,代码行数:18,代码来源:Cell.cs

示例11: TestStartsWithOperatorString

        public void TestStartsWithOperatorString()
        {
            const string f = "f";
            var source = new[]
                             {
                                 new TestSource {String = "foo", Int = 1}, new TestSource {String = "bar", Int = 2},
                                 new TestSource {String = "baz", Int = 3}, new TestSource {String = "fii", Int = 4},
                                 new TestSource {String = "fuu", Int = 5}, new TestSource {String = "zap", Int = 6},
                                 new TestSource {String = "faa", Int = 7}
                             };

            var expectedResultList = source.Where(t => t.String.StartsWith(f)).ToList();

            var filter = new FilterSetting { OperatorName = FilterOperators.StartsWithOperator, PropertyPath = "String", Value = f };

            var result = _builder.Filter(source.AsQueryable(), new[] { filter });

            TestUtil.AssertModels(expectedResultList, result.ToList());
        }
开发者ID:OldWiseLlama,项目名称:DynamicExpressionBuilder,代码行数:19,代码来源:FilterExpressionBuilderTests.cs

示例12: correct_iquerable_should_be_returned

        public void correct_iquerable_should_be_returned()
        {
            var source = new[]
            {
                new DummyDocument
                {
                    Id = 1,
                    Name = "First",
                    Count = 2
                },
                new DummyDocument
                {
                    Id = 2,
                    Name = "Middle",
                    Count = 3
                },
                new DummyDocument
                {
                    Id = 3,
                    Name = "Last",
                    Count = 3
                },
                new DummyDocument
                {
                    Id = 4,
                    Name = "Last",
                    Count = 4
                }
            }
                .AsQueryable();

            var filterList = new List<FilterByRequest>()
            {
                new FilterByRequest("name", "Last"),
                new FilterByRequest("count", "3"),
            };

            var filteredData = source.DynamicFiltering(filterList);
            var expectedFilteredData = source.Where(document => document.Id == 3);
            filteredData.SequenceEqual(expectedFilteredData).Should().BeTrue();
        }
开发者ID:skynyrd,项目名称:Hepsi.Extensions,代码行数:41,代码来源:with_a_list_of_filters.cs

示例13: OneInactiveUser

        public void OneInactiveUser()
        {
            // Arrange
            IEnumerable<User> users = new[]
            {
                new User {Id = 1, FirstName = "User1", LastName = "User1", Email = "[email protected]", IsActive = true},
                new User {Id = 2, FirstName = "User2", LastName = "User2", Email = "[email protected]", IsActive = true},
                new User {Id = 3, FirstName = "User3", LastName = "User3", Email = "[email protected]", IsActive = false}
            };

            ApplicationDbContext dbContext = new Mock<ApplicationDbContext>("Test")
                .SetupDbContextData(x => x.Users, users)
                .Build();

            // Act
            InactiveUsersQuery query = new InactiveUsersQuery(dbContext);
            IEnumerable<User> result = query.Execute();

            // Assert
            CollectionAssert.AreEqual(users.Where(x => x.IsActive == false).ToArray(), result.ToArray());
        }
开发者ID:Code-First,项目名称:CQS-Sample,代码行数:21,代码来源:InactiveUsersQueryTests.cs

示例14: CaseOne

        public static void CaseOne()
        {
            List<CardTemplate> HandCards_BoardCards = MainLists.HandCards_BoardCards;

            int X_Config_Drop = ValueReader.ValueIgnorer.GetXDrop;

            //card is X drop and hand contains "x - 1 drop" and "x - 2 drop"
            if (ValueReader.ValueIgnorer.IgnoreValueIfCardIsX_DropEtc
                &&
                HandCards_BoardCards.Any(x => new NeutralMinion(x).minionBoardCard != null && x.Cost == X_Config_Drop)
                &&
                HandCards_BoardCards.Any(x => new NeutralMinion(x).minionBoardCard != null && x.Cost == X_Config_Drop - 1)
                &&
                HandCards_BoardCards.Any(x => new NeutralMinion(x).minionBoardCard != null && x.Cost == X_Config_Drop - 2)
                && !Combos.alreadyFoundOneCombo)
            {
                Combos.alreadyFoundOneCombo = true;
                //add BEST x - 1 drop and x - 2 drop
                var bestXDrop =
                        HandCards_BoardCards.Where(x => new NeutralMinion(x).minionBoardCard != null && x.Cost == X_Config_Drop).
                            OrderBy(x => new NeutralMinion(x).thisCardValue).Last();
                var bestX_1Drop =
                        HandCards_BoardCards.Where(x => new NeutralMinion(x).minionBoardCard != null && x.Cost == X_Config_Drop - 1).
                            OrderBy(x => new NeutralMinion(x).thisCardValue).Last();
                var bestX_2Drop =
                        HandCards_BoardCards.Where(x => new NeutralMinion(x).minionBoardCard != null && x.Cost == X_Config_Drop - 2).
                            OrderBy(x => new NeutralMinion(x).thisCardValue).Last();

                var bestDrops = new[] { bestXDrop, bestX_1Drop, bestX_2Drop };

                foreach (var drop in bestDrops.Where(x => !MainLists.chosenCards.Contains(BoardToMulliganCard(x))))
                {
                    string dropAsString = drop.Id.ToString();
                    MainLists.chosenCards.Add(CardTemplate.StringToCard(dropAsString));
                    MainLists.blackList.Add(drop.Id.ToString());
                }
            }
        }
开发者ID:DanThePman,项目名称:Hearthstone,代码行数:38,代码来源:Combos.cs

示例15: TestOrAndCombination

        public void TestOrAndCombination()
        {
            var source = new[]
                             {
                                 new TestSource {String = "foo", Int = 1}, new TestSource {String = "bar", Int = 2},
                                 new TestSource {String = "baz", Int = 3}, new TestSource {String = "fii", Int = 4},
                                 new TestSource {String = "baz", Int = 5}, new TestSource {String = "fuu", Int = 6},
                                 new TestSource {String = "zap", Int = 7}, new TestSource {String = "faa", Int = 8}
                             };

            var expectedResultList = source.Where(t => t.String.StartsWith("f") && (t.String.EndsWith("i") || t.String.EndsWith("a"))).ToList();

            var startsWithFilter = new FilterSetting { OperatorName = FilterOperators.StartsWithOperator, PropertyPath = "String", Value = "f" };
            var endsWith1Filter = new FilterSetting { OperatorName = FilterOperators.EndsWithOperator, PropertyPath = "String", Value = "i" };
            var endsWith2Filter = new FilterSetting { OperatorName = FilterOperators.EndsWithOperator, PropertyPath = "String", Value = "a" };

            var orFilter = new FilterSetting { OrConnectedFilters = new List<FilterSetting> { endsWith1Filter, endsWith2Filter } };

            var result = _builder.Filter(source.AsQueryable(), new[] { startsWithFilter, orFilter });

            TestUtil.AssertModels(expectedResultList, result.ToList());
        }
开发者ID:OldWiseLlama,项目名称:DynamicExpressionBuilder,代码行数:22,代码来源:FilterExpressionBuilderTests.cs


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