本文整理汇总了C#中IList.Where方法的典型用法代码示例。如果您正苦于以下问题:C# IList.Where方法的具体用法?C# IList.Where怎么用?C# IList.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IList
的用法示例。
在下文中一共展示了IList.Where方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initialize
public void Initialize()
{
order = new Order();
order.OrderEntries = null;
order.SentDate = DateTime.Now;
order.Id = 10;
order.User = null;
userAcc = new UserAccount();
userAcc.Id = 5;
orders = new List<Order>();
orderManagementDaoMock = _factory.CreateMock<IOrderManagementDao>();
oms.OrderManagementDao = orderManagementDaoMock.MockObject;
// NMock.Actions.InvokeAction saveOrder = new NMock.Actions.InvokeAction(new Action(() => orders = new List<Order>(){order}));
// orderManagementDaoMock.Expects.Any.MethodWith(x => x.SaveOrUpdate(order)).Will(saveOrder);
orderInformationDaoMock = _factory.CreateMock<IOrderInformationsDao>();
ois.OrderInformationDao = orderInformationDaoMock.MockObject;
orderInformationDaoMock.Expects.Any.MethodWith<Order>(x => x.GetOrderById(order.Id)).WillReturn(order);
orderInformationDaoMock.Expects.Any.MethodWith<Order>(x => x.GetOrderById(-1)).WillReturn(null);
// orderInformationDaoMock.Expects.Any.MethodWith(x => x.GetOrdersByUserId(userAcc.Id)).WillReturn(orders.Where(x => x.User.Id == userAcc.Id));
orderInformationDaoMock.Expects.Any.MethodWith(x => x.GetOrdersByUserId(-1)).WillReturn(orders.Where(x => x.User.Id == userAcc.Id));
orderInformationDaoMock.Expects.Any.Method(x => x.GetUndeliveredOrders()).WillReturn(orders.Where(x => x.Status != Order.OrderState.DELIVERED));
orderInformationDaoMock.Expects.Any.MethodWith(x => x.GetUndeliveredByUserId(userAcc.Id)).WillReturn(orders.Where(x => x.Status != Order.OrderState.DELIVERED && x.User.Id == userAcc.Id));
//orderInformationDaoMock.Expects.Any.MethodWith(x => x.GetDeliveredOrdersByUserId(userAcc.Id)).WillReturn(orders.Where(x => x.Status == Order.OrderState.DELIVERED && x.User.Id == userAcc.Id));
}
示例2: ComponentInfo
public ComponentInfo(string id, Type serviceType, Type componentType, IList<IPolicy> policies, bool lifeManagement)
{
id.ThrowIfNullArgument(nameof(id));
_id = id;
_serviceType = serviceType;
_componentType = componentType;
if (_serviceType == null && _componentType == null)
ExceptionHelper.ThrowInfoNotComplete(_id);
_lifecycleManagement = lifeManagement;
_buildPolicies = new List<IPolicy>();
var preCreation = policies.Where(p => p.Stage == Stages.PreCreation).ToArray();
if (preCreation.Length == 0)//If no policy define for PreCreation, stateless will be default policy
_buildPolicies.Add(new StatelessPolicy());
else
_buildPolicies.AddRange(preCreation);
var creation = policies.Where(p => p.Stage == Stages.Creation).ToArray();
if (creation.Length == 0)//If no policy define for Creation, activator will be default policy
_buildPolicies.Add(new ActivatorPolicy());
else
_buildPolicies.AddRange(creation);
_buildPolicies.AddRange(policies.Where(p => p.Stage == Stages.Initialization || p.Stage == Stages.PostInitialization));
}
示例3: Upgrade
public override bool Upgrade(PackageSession session, ILogger log, Package dependentPackage, PackageDependency dependency, Package dependencyPackage, IList<PackageLoadingAssetFile> assetFiles)
{
// Paradox 1.1 projects didn't have their dependency properly updated (they might have been marked as 1.0).
// We know they are 1.1 only because there is a .props file.
// This check shouldn't be necessary from 1.2.
var packagePath = dependentPackage.FullPath;
var propsFilePath = UPath.Combine(packagePath.GetParent(), (UFile)(packagePath.GetFileName() + ".props"));
if (!File.Exists(propsFilePath) && dependency.Version.MinVersion < new PackageVersion("1.1.0-beta"))
{
log.Error("Can't upgrade old projects from {0} 1.0 to 1.1", dependency.Name);
return false;
}
// Nothing to do for now, most of the work is already done by individual asset upgraders
// We can later add logic here for package-wide upgrades (i.e. GameSettingsAsset)
if (dependency.Version.MinVersion < new PackageVersion("1.2.0-beta"))
{
// UIImageGroups and SpriteGroups asset have been merged into a single SpriteSheet => rename the assets and modify the tag
var uiImageGroups = assetFiles.Where(f => f.FilePath.GetFileExtension() == ".pdxuiimage");
var spitesGroups = assetFiles.Where(f => f.FilePath.GetFileExtension() == ".pdxsprite");
RenameAndChangeTag(assetFiles, uiImageGroups, "!UIImageGroup");
RenameAndChangeTag(assetFiles, spitesGroups, "!SpriteGroup");
}
return true;
}
示例4: HighestCard
public ICard HighestCard(IList<ICard> cards)
{
//TODO use aggregates instead:
//ICard highestTrumpCard =
// _Cards.Where(a => a.Suit == _Trump).Aggregate(card,
// (curMin, x) =>
// (x.Rank > curMin.Rank ? x : curMin));
var trumpCards = cards.Where(a => a.Suit == _Trump).ToList();
if (trumpCards.Any())
{
ICard highestTrumpCard = trumpCards[0];
foreach (var card in trumpCards)
{
if (card.Rank > highestTrumpCard.Rank)
{
highestTrumpCard = card;
}
}
return highestTrumpCard;
}
var firstSuit = cards[0].Suit;
return cards.Where(a => a.Suit == firstSuit).Aggregate(
(curMin, x) =>
(x.Rank > curMin.Rank ? x : curMin));
}
示例5: Deal
/// <summary>
/// Deals the specified players.
/// </summary>
/// <param name="players">The players.</param>
/// <param name="cardsOnBoard">The cards on board.</param>
public void Deal(IList<IParticipant> players, ICard[] cardsOnBoard)
{
this.Shuffle();
int toTakeFromDeckIndex = 0;
// deal cards to players
foreach (IParticipant player in players.Where(p => p.IsInGame))
{
this.DealCardsToPlayers(player, ref toTakeFromDeckIndex);
}
// place cards on board
Point boardCardsPosition = GlobalVariables.BoardCardsPlace;
int positionCardChangeX = boardCardsPosition.X;
for (int i = 0; i < 5; i++)
{
this.DealCardsOnBoard(
cardsOnBoard,
i,
ref toTakeFromDeckIndex,
boardCardsPosition,
ref positionCardChangeX);
}
// turn the player cards up
foreach (var player in players.Where(p => p.IsInGame && p is Player))
{
player.Hand.CurrentCards[0].IsFacingUp = true;
player.Hand.CurrentCards[1].IsFacingUp = true;
}
}
示例6: SortGraph
IEnumerable<ModuleDefMD> SortGraph(IEnumerable<ModuleDefMD> roots, IList<DependencyGraphEdge> edges)
{
var visited = new HashSet<ModuleDefMD>();
var queue = new Queue<ModuleDefMD>(roots);
do {
while (queue.Count > 0) {
var node = queue.Dequeue();
visited.Add(node);
Debug.Assert(!edges.Where(edge => edge.To == node).Any());
yield return node;
foreach (DependencyGraphEdge edge in edges.Where(edge => edge.From == node).ToList()) {
edges.Remove(edge);
if (!edges.Any(e => e.To == edge.To))
queue.Enqueue(edge.To);
}
}
if (edges.Count > 0) {
foreach (var edge in edges) {
if (!visited.Contains(edge.From)) {
queue.Enqueue(edge.From);
break;
}
}
}
} while (edges.Count > 0);
}
示例7: UpdateInvoiceDetails
public void UpdateInvoiceDetails(IList<InvoiceDetail> invoiceDetails, IList<int> deleteIds)
{
Process(() =>
{
if (invoiceDetails != null && invoiceDetails.Count > 0)
{
var ids = invoiceDetails.Select(x => x.Id);
var invoicesInDb = invoiceDetailRepository.Query().Where(x => ids.Contains(x.Id)).ToList();
var idsInDb = invoicesInDb.Select(x => x.Id);
foreach (var invoice in invoicesInDb)
{
var item = invoiceDetails.Where(x => x.Id == invoice.Id).First();
invoice.Description = item.Description;
invoice.Quantity = item.Quantity;
invoice.Price = item.Price;
}
var invoicesNotInDb = invoiceDetails.Where(x => !idsInDb.Contains(x.Id));
foreach (var invoice in invoicesNotInDb)
{
invoiceDetailRepository.Insert(invoice);
}
}
if (deleteIds != null && deleteIds.Count > 0)
{
DeleteInvoiceDetails(deleteIds);
}
this.unitOfWork.Commit();
});
}
示例8: Calculate
public async Task<IssuesCollectionStatistics> Calculate(IList<JiraIssue> issues)
{
if(issues == null || issues.Any() == false)
return null;
return await Task.Factory.StartNew(() =>
{
return new IssuesCollectionStatistics
{
IssuesCount = issues.Count(),
ResolvedIssuesCount = issues.Where(i => i.Resolved.HasValue).Count(),
UnresolvedIssuesCount = issues.Where(i => i.Resolved.HasValue == false).Count(),
AverageResolutionTimeHours = issues
.Where(i => i.Resolved.HasValue)
.Select(i => (i.Resolved.Value - i.Created).TotalHours).Average(),
MaxResolutionTimeHours = issues
.Where(i => i.Resolved.HasValue)
.Select(i => (i.Resolved.Value - i.Created).TotalHours).Max(),
TotalStorypoints = issues.Sum(i => i.StoryPoints),
AverageStorypointsPerTask = issues.Average(i => i.StoryPoints),
AverageSubtasksCount = issues.Average(i => i.Subtasks),
EpicsInvolved = issues.Select(i => i.EpicLink).Distinct().Count(),
DistinctReporters = issues.Select(i => i.Reporter).Distinct().Count()
};
});
}
示例9: FormatDeletePatterns
private string FormatDeletePatterns(IList<ITriple> deletePatterns, string updateGraphUri)
{
var deleteCmds = new StringBuilder();
int propId = 0;
if (deletePatterns.Any(p => IsGraphTargeted(p) && IsGrounded(p)))
{
deleteCmds.AppendLine("DELETE DATA {");
foreach (var patternGroup in deletePatterns.Where(p => IsGraphTargeted(p) && IsGrounded(p)).GroupBy(p=>p.Graph))
{
deleteCmds.AppendFormat("GRAPH <{0}> {{", patternGroup.Key);
deleteCmds.AppendLine();
foreach (var deletePattern in patternGroup)
{
AppendTriplePattern(deletePattern, deleteCmds);
}
deleteCmds.AppendLine("}");
}
deleteCmds.AppendLine("};");
}
foreach (var deletePattern in deletePatterns.Where(p=>IsGraphTargeted(p) && !IsGrounded(p)))
{
deleteCmds.AppendFormat("WITH <{0}> DELETE {{ {1} }} WHERE {{ {1} }};",
deletePattern.Graph, FormatDeletePattern(deletePattern, ref propId));
}
if (deletePatterns.Any(p => !IsGraphTargeted(p) && IsGrounded(p)))
{
// Delete from default graph
deleteCmds.AppendLine("DELETE DATA {");
foreach (var p in deletePatterns.Where(p => !IsGraphTargeted(p) && IsGrounded(p)))
{
AppendTriplePattern(p, deleteCmds);
}
// If an update graph is specified delete from that too
if (updateGraphUri != null)
{
deleteCmds.AppendFormat("GRAPH <{0}> {{", updateGraphUri);
deleteCmds.AppendLine();
foreach (var p in deletePatterns.Where(p => !IsGraphTargeted(p) && IsGrounded(p)))
{
AppendTriplePattern(p, deleteCmds);
}
deleteCmds.AppendLine("}");
}
deleteCmds.AppendLine("};");
}
foreach (var deletePattern in deletePatterns.Where(p => !IsGraphTargeted(p) && !IsGrounded(p)))
{
var cmd = String.Format("DELETE {{ {0} }} WHERE {{ {0} }};",
FormatDeletePattern(deletePattern, ref propId));
deleteCmds.AppendLine(cmd);
if (updateGraphUri != null)
{
deleteCmds.AppendFormat("WITH <{0}> ", updateGraphUri);
deleteCmds.AppendLine(cmd);
}
}
return deleteCmds.ToString();
}
示例10: PrintReportFooter
public virtual void PrintReportFooter(StreamWriter streamWriter, IList<AllItem> allItems)
{
int drCount = allItems.Count(ai => ai.Classification == "Dr");
int crCount = allItems.Count(ai => ai.Classification == "Cr");
decimal drAmount = allItems.Where(ai => ai.Classification == "Dr").Sum(ai => ai.Amount);
decimal crAmount = allItems.Where(ai => ai.Classification == "Cr").Sum(ai => ai.Amount);
streamWriter.WriteLine(string.Format(this.reportFooterFormat, drCount, drAmount, crCount, crAmount));
}
示例11: GetRuleViolations
private IEnumerable<FieldDeclarationSyntax> GetRuleViolations(IList<dynamic> fieldsInfo)
{
if (fieldsInfo.Any(f => !f.IsCollection))
{
return fieldsInfo.Where(f => f.IsCollection).Select(f => f.Syntax as FieldDeclarationSyntax);
}
if (fieldsInfo.Any(f => f.IsCollection))
{
return fieldsInfo.Where(f => f.IsCollection).Skip(1).Select(f => f.Syntax as FieldDeclarationSyntax);
}
return new List<FieldDeclarationSyntax>();
}
示例12: SetChartModel
private static AmazonChartModel SetChartModel(DateTime from, DateTime to, IList<KeyValuePair<DateTime, decimal>> items)
{
var data = new Dictionary<string, decimal>();
var labels = new List<string>();
var ts = to - from;
var factor = (ts.Days/7)+1;
var oldDate = DateTime.Parse(from.Date.ToString());
var currentDate = oldDate;
for (var i = 0; i < 7; i++)
{
oldDate = currentDate;
currentDate = oldDate.AddDays(ts.Days <= 7 ? 1 : factor);
labels.Add(oldDate.ToString("dd/MM"));
data.Add(oldDate.ToString("dd/MM"), i == 0
? items.Where(x => x.Key.Date == currentDate.Date).Sum(x => x.Value)
: items.Where(x => oldDate.Date <= x.Key && x.Key <= currentDate.Date)
.Sum(x => x.Value));
}
return new AmazonChartModel
{
Labels = labels,
Data = data
};
}
示例13: AddButtons
public void AddButtons(IList<CustomMenu> menuList)
{
var rootMenus = menuList.Where(p => !p.ParentMenuID.HasValue).Select(p => new MenuButton
{
ID = p.ID,
Type = MenuTypeToString((EnumMenuType)p.Type),
Name = p.Name,
Key = p.Key,
Url = p.View_Url
}).ToList();
var childrenMenu = menuList.Where(p => p.ParentMenuID.HasValue).GroupBy(p => p.ParentMenuID);
foreach (var menuButton in rootMenus)
{
if (!childrenMenu.Any(p => p.Key == menuButton.ID))
{
continue;
}
var subMenus = childrenMenu.FirstOrDefault(p => p.Key == menuButton.ID);
menuButton.SubButton = subMenus.Select(p => new MenuButton
{
Type = MenuTypeToString((EnumMenuType)p.Type),
Name = p.Name,
Key = p.Key,
Url = p.View_Url
}).ToList();
menuButton.Key = string.Empty;
menuButton.Type = string.Empty;
menuButton.Url = string.Empty;
}
Button = rootMenus;
}
示例14: TryFindMatchingArgument
private static bool TryFindMatchingArgument(IList<string> args, string argumentKey, out string arg)
{
arg = null;
//if the key ends with a colon (:) that means it has an associated value, otherwise there should be no additional characters
//and the key is the entire argument
//
IEnumerable<string> matchingArgs;
if(argumentKey.EndsWith(":", StringComparison.OrdinalIgnoreCase) )
{
matchingArgs = args.Where(a => a.StartsWith(argumentKey, StringComparison.OrdinalIgnoreCase));
}
else
{
matchingArgs = args.Where(a => a.Equals(argumentKey, StringComparison.OrdinalIgnoreCase));
}
if (matchingArgs.Count() > 1)
{
throw new ApplicationException(string.Format("Multiple arguments of name {0} specified", argumentKey));
}
else if (matchingArgs.Count() == 1)
{
arg = matchingArgs.First();
return true;
}
return false;
}
示例15: CalculateUnverifiedRank
public static int CalculateUnverifiedRank(this Competitor competitor , IList<Match> matches)
{
return (competitor.Rating +
matches.Where(x => x.Loser.ProfileUserId == competitor.ProfileUserId && !x.IsResolved)
.Sum(x => x.LoserRatingDelta) +
matches.Where(x => x.Winner.ProfileUserId == competitor.ProfileUserId && !x.IsResolved)
.Sum(x => x.WinnerRatingDelta));
}