本文整理汇总了C#中IList.GroupBy方法的典型用法代码示例。如果您正苦于以下问题:C# IList.GroupBy方法的具体用法?C# IList.GroupBy怎么用?C# IList.GroupBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IList
的用法示例。
在下文中一共展示了IList.GroupBy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPowerScores
public static int GetPowerScores(IList<string> powerPhrases)
{
return powerPhrases
.GroupBy(e => e)
.Select(e => new {PowerPhrase = e.Key, Amount = e.Count()})
.Aggregate(0, (sum, info) => sum + GetPowerScore(info.PowerPhrase, info.Amount));
}
示例2: DashboardViewModel
public DashboardViewModel(IEnumerable<WebSite> websites, IList<SyncStatus> syncStatuses)
{
Instances = syncStatuses.GroupBy(s => s.RoleInstanceId)
.Select(s => new InstanceViewModel {Name = s.Key, IsOnline = s.First().IsOnline})
.ToList();
Sites = websites.Select(w => new SiteViewModel
{
Id = w.Id,
Name = w.Name,
SyncStatus = Instances.ToDictionary(
i => i.Name,
i => syncStatuses
.Where(s => s.SiteName.Equals(w.Name, StringComparison.InvariantCultureIgnoreCase)
&& s.RoleInstanceId.Equals(i.Name, StringComparison.InvariantCultureIgnoreCase)
)
.Select(s =>
new SiteSyncViewModel
{
SyncError = s.LastError != null ? s.LastError.Message : null,
SyncStatus = s.Status.ToString(),
SyncTime = s.SyncTimestamp
}
)
.FirstOrDefault() ?? new SiteSyncViewModel{SyncStatus = "NotDeployed"}
)
});
}
示例3: GenerateDateRangeCollection
private void GenerateDateRangeCollection()
{
_dayForecastCollection = new List<DayForecast>();
_startDateDaysInMonth = DateTime.DaysInMonth(_startDate.Year, _startDate.Month);
_endDateDaysInMonth = DateTime.DaysInMonth(_endDate.Year, _endDate.Month);
_monthDifference = Microsoft.VisualBasic.DateAndTime.DateDiff(Microsoft.VisualBasic.DateInterval.Month, _startDate, _endDate);
ProcessDayForecastCollection(_startDateDaysInMonth, _startDate, _dayForecastCollection);
for (int i = 1; i < _monthDifference; i++)
{
DateTime inbetweenDt = _startDate.AddMonths(i);
var inbetweenDtDaysInMonth = DateTime.DaysInMonth(inbetweenDt.Year, inbetweenDt.Month);
ProcessDayForecastCollection(inbetweenDtDaysInMonth, inbetweenDt, _dayForecastCollection);
}
List<DayForecast> weekItem = new List<DayForecast>();
_weekDayForecastCollection = new List<List<DayForecast>>();
foreach(var df in _dayForecastCollection)
{
weekItem.Add(df);
if (df.FullDayOfTheWeek == _dayForecastConfiguration.DayEndOfWeek)
{
_weekDayForecastCollection.Add(weekItem);
weekItem = new List<DayForecast>();
}
}
_week = _dayForecastCollection.GroupBy(d => d.FullDayOfTheWeek).Select(gd => gd.Key).ToList();
//here
}
示例4: MergeReceiptItems
IList<ReceiptItem> MergeReceiptItems(IList<BoughtProduct> boughtProducts)
{
string[] barcodes = boughtProducts.Select(bp => bp.Barcode).Distinct().ToArray();
Dictionary<string, Product> boughtProductSet = m_productRepository
.GetByBarcodes(barcodes)
.ToDictionary(p => p.Barcode, p => p);
Dictionary<string,int> boughtDictionary = boughtProducts.GroupBy(bp => bp.Barcode)
.ToDictionary(g => g.Key, g => g.Sum(bp => bp.Amount));
var buyTwoGetOne = new BuyTwoGetOne(m_promotionRepository, m_productRepository);
Dictionary<string, decimal> boughtProductPromoted = buyTwoGetOne.GetPromoted(boughtDictionary);
return boughtProducts
.GroupBy(bp => bp.Barcode)
.Select(g => new ReceiptItem(boughtProductSet[g.Key], g.Sum(bp => bp.Amount),boughtProductPromoted[g.Key]))
.ToArray();
}
示例5: AddComments
public IList<AcceptedUserComment> AddComments(string type, string clientToken, IList<UserComment> userComments)
{
if (userComments == null || userComments.Count == 0)
return null;
var acceptedComments = new List<AcceptedUserComment>();
var commentsForEvents = userComments.GroupBy(x=>x.eventId);
foreach (var eventGroup in commentsForEvents)
{
var userInfo = GetUserEventInfo(eventGroup.Key);
var dddEvent = eventsService.GetServerEventData(eventGroup.Key);
var eventDetail = eventsService.GetEventDetail(dddEvent);
if (dddEvent.IsActive)
{
var accepted = addComments(type, eventGroup.Key, eventDetail, userInfo != null ? userInfo.UserName : "", userInfo != null ? userInfo.UserToken : null, clientToken, eventGroup.ToList());
acceptedComments.AddRange(accepted);
}
else
{
//We don't want the client to keep sending the same message, so respond that it is accepted (even though it's not)
var accepted = eventGroup.Select(x => new AcceptedUserComment
{
eventId = x.eventId,
id = x.id,
sessionId = x.sessionId
});
return accepted.ToList();
}
}
return acceptedComments;
}
示例6: OnReferenceLocationsChanged
private void OnReferenceLocationsChanged(object sender, IList<InlineRenameLocation> renameLocations)
{
int totalFilesCount = renameLocations.GroupBy(s => s.Document).Count();
int totalSpansCount = renameLocations.Count;
UpdateSearchText(totalSpansCount, totalFilesCount);
}
示例7: MainWindow
public MainWindow()
{
InitializeComponent();
Loaded += (sender, e) => ClearValue(SizeToContentProperty);
_allControllerViewModels =
(from type in GetType().Assembly.GetTypes()
where !type.IsInterface && typeof(IController).IsAssignableFrom(type)
let viewModel = new ControllerViewModel((IController)Activator.CreateInstance(type))
orderby viewModel.SortIndex, viewModel.Library, viewModel.Description
select viewModel).ToList();
_allControllerViewModels.First().IsChecked = true;
ControllerGroups.ItemsSource = _allControllerViewModels.GroupBy(viewModel => viewModel.Library);
_allResolutionViewModels = new[] {
new ResolutionViewModel(800, 600, 50, 42),
new ResolutionViewModel(1024, 768, 64, 54),
new ResolutionViewModel(1280, 1024, 80, 73),
new ResolutionViewModel(1440, 900, 90, 64),
};
_allResolutionViewModels.Last(
res => res.Width <= SystemParameters.PrimaryScreenWidth &&
res.Height <= SystemParameters.PrimaryScreenHeight).IsChecked = true;
Resolutions.ItemsSource = _allResolutionViewModels;
RunResults.ItemsSource = _runResults;
}
示例8: Validate
public IEnumerable<ValidationError> Validate(IList<Benchmark> benchmarks)
{
var errors = new List<ValidationError>();
foreach (var typeGroup in benchmarks.GroupBy(benchmark => benchmark.Target.Type))
{
object benchmarkTypeInstance = null;
if (!TryCreateBenchmarkTypeInstance(typeGroup.Key, typeGroup, errors, out benchmarkTypeInstance))
{
continue;
}
if (!TryToSetParamsFields(benchmarkTypeInstance, typeGroup, errors))
{
continue;
}
if (!TryToSetParamsProperties(benchmarkTypeInstance, typeGroup, errors))
{
continue;
}
if (!TryToCallSetup(benchmarkTypeInstance, typeGroup, errors))
{
continue;
}
ExecuteBenchmarks(benchmarkTypeInstance, typeGroup, errors);
}
return errors;
}
示例9: GetSets
protected internal IEnumerable<IGrouping<CardFigure, Card>> GetSets(IList<Card> cards, int cardsInSet)
{
// broke my original linq up so it can be debugged. This is a good idea? or bad idea? Then put it back together
return cards
.GroupBy<Card, CardFigure>(key => key.Figure)
.Where<IGrouping<CardFigure, Card>>(group => group.Count<Card>() == cardsInSet);
}
示例10: Validate
public IEnumerable<ValidationError> Validate(IList<Benchmark> benchmarks)
{
#if CORE
yield break; // todo: implement when it becomes possible
#else
foreach (var group in benchmarks.GroupBy(benchmark => benchmark.Target.Type.Assembly()))
{
foreach (var referencedAssemblyName in group.Key.GetReferencedAssemblies())
{
var referencedAssembly = Assembly.Load(referencedAssemblyName);
if (IsJITOptimizationDisabled(referencedAssembly))
{
yield return new ValidationError(
TreatsWarningsAsErrors,
$"Assembly {group.Key} which defines benchmarks references non-optimized {referencedAssemblyName.Name}");
}
}
if (IsJITOptimizationDisabled(group.Key))
{
yield return new ValidationError(
TreatsWarningsAsErrors,
$"Assembly {group.Key} which defines benchmarks is non-optimized");
}
}
#endif
}
示例11: SortItems
/// <summary>
/// Sort the items by their priority and their index they currently exist in the collection
/// </summary>
/// <param name="files"></param>
/// <returns></returns>
public static IList<IClientDependencyFile> SortItems(IList<IClientDependencyFile> files)
{
//first check if each item's order is the same, if this is the case we'll make sure that we order them
//by the way they were defined
if (!files.Any()) return files;
var firstPriority = files.First().Priority;
if (files.Any(x => x.Priority != firstPriority))
{
var sortedOutput = new List<IClientDependencyFile>();
//ok they are not the same so we'll need to sort them by priority and by how they've been entered
var groups = files.GroupBy(x => x.Priority).OrderBy(x => x.Key);
foreach (var currentPriority in groups)
{
//for this priority group, we'll need to prioritize them by how they are found in the files array
sortedOutput.AddRange(currentPriority.OrderBy(files.IndexOf));
}
return sortedOutput;
}
//they are all the same so we can really just return the original list since it will already be in the
//order that they were added.
return files;
}
示例12: SetUp
public void SetUp()
{
_listaGruppi = new List<SferaAziendeDTO>
{
new SferaAziendeDTO {Codice = "AZI01", Gruppo = "GR1", Id = 1},
new SferaAziendeDTO {Codice = "AZI02", Gruppo = "GR1", Id = 2},
new SferaAziendeDTO {Codice = "AZI03", Gruppo = "GR2", Id = 3},
new SferaAziendeDTO {Codice = "AZI04", Gruppo = "GR2", Id = 4},
new SferaAziendeDTO {Codice = "AZI05", Gruppo = "GR3", Id = 5},
new SferaAziendeDTO {Codice = "AZI06", Gruppo = "GR3", Id = 6},
new SferaAziendeDTO {Codice = "AZI07", Gruppo = "GR4", Id = 7},
new SferaAziendeDTO {Codice = "AZI08", Gruppo = "GR4", Id = 8}
};
_aziendaService = MockRepository.GenerateStub<IAziendaService>();
_aziendaService.Stub(x => x.GetAllGruppi()).Return(_listaGruppi.GroupBy(item => item.Gruppo).ToList());
_richiestaImportazioneDocumentiBolletteService = MockRepository.GenerateMock<IRichiestaImportazioneDocumentiBolletteService>();
_importazioneDocumentiBolletteService = MockRepository.GenerateMock<IImportazioneDocumentiBolletteService>();
_windsorContainer = MockRepository.GenerateStub<IWindsorContainer>();
_windsorContainer.Stub(x => x.Resolve<IRichiestaImportazioneDocumentiBolletteService>()).Return(_richiestaImportazioneDocumentiBolletteService);
_windsorContainer.Stub(x => x.Resolve<IImportazioneDocumentiBolletteService>()).Return(_importazioneDocumentiBolletteService);
_iocContainerService = MockRepository.GenerateStub<IIocContainerService>();
_iocContainerService.Stub(x => x.GetContainerFromKey(Arg<string>.Is.Anything)).Return(_windsorContainer);
_utenzaRicezioneDocumentoJob = new UtenzaRicezioneDocumentoJob(_aziendaService, _iocContainerService);
}
示例13: DesignTimeCompilationException
public DesignTimeCompilationException(IList<DiagnosticMessage> compileResponseErrors)
: base(string.Join(Environment.NewLine, compileResponseErrors.Select(e => e.FormattedMessage)))
{
CompilationFailures = compileResponseErrors.GroupBy(g => g.SourceFilePath, StringComparer.OrdinalIgnoreCase)
.Select(g => new CompilationFailure(g.Key, g))
.ToArray();
}
示例14: GetCustomersStatistics
//Get aggregates i.e WinPercentage and AverageBet for each customer in provided list of bets
public IList<Customer> GetCustomersStatistics(IList<Bet> settledBets)
{
var customers = new List<Customer>();
customers = settledBets.GroupBy(b => b.CustomerCode)
.Select(group => new Customer(group.Key, (group.Count(g => g.Win > 0) * 100) / group.Count(), Math.Round(group.Average(g => g.Stake), 2))).ToList();
return customers.OrderByDescending(o=>o.WinPercentage).ToList();
}
示例15: SearchRootNode
public SearchRootNode(string title, IList<SearchResultMatch> results)
{
this.Title = title;
this.results = results.Select(r => new SearchResultNode(r)).ToArray();
fileCount = results.GroupBy(r => r.FileName).Count();
this.Children = this.results;
this.IsExpanded = true;
}