本文整理汇总了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);
}
示例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();
}
示例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());
}
示例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);
}
示例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;
}
示例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));
}
示例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);
}
}
示例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;
}
示例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();
}
示例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);
}
示例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());
}
示例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();
}
示例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());
}
示例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());
}
}
}
示例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());
}