本文整理汇总了C#中IDictionary.GroupBy方法的典型用法代码示例。如果您正苦于以下问题:C# IDictionary.GroupBy方法的具体用法?C# IDictionary.GroupBy怎么用?C# IDictionary.GroupBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDictionary
的用法示例。
在下文中一共展示了IDictionary.GroupBy方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MergeAllTranslation
public void MergeAllTranslation(IDictionary<string, TemplateItem> items)
{
foreach (var language in _repository.GetAvailableLanguages())
{
var filesNames = items.GroupBy(x => x.Value.FileName).Select(x => x.Key).ToList();
MergeTranslation(items, _repository.GetTranslation(language.LanguageShortTag, filesNames, false));
}
}
示例2: GetOpNodeProbabilities
public static double[] GetOpNodeProbabilities(IDictionary<Operator, double> operatorAndProbabilityMap)
{
return operatorAndProbabilityMap
.GroupBy(e => e.Key.Arity)
.Where(g => g.Key > 0)
.OrderBy(g => g.Key)
.Select(g => g.Sum(e => e.Value))
.Where(p => p > 0)
.ToArray();
}
示例3: GetRepeatingFolds
public IEnumerable<TextPosition> GetRepeatingFolds(IDictionary<TextPosition, TextPosition> folds) =>
folds.GroupBy(pair => pair.Key.Line)
.Where(group => group.Count() > 1)
.SelectMany(group => group)
.Select(pair => pair.Key);
示例4: Write
public void Write(IDictionary<Channel, double[]> output)
{
var ns = output.Values.Select(v => v.Count()).Distinct().ToList();
if (ns.Count() > 1)
throw new ArgumentException("Preload sample buffers must be homogenous in length");
int nsamples = ns.First();
var groups = output.GroupBy(kv => kv.Key.Type).ToDictionary(g => g.Key, g => g.ToDictionary(kv => kv.Key, kv => kv.Value));
var tasks = new List<Task>();
if (groups.ContainsKey(ChannelType.AO))
tasks.Add(Task.Factory.StartNew(() => WriteAnalog(groups[ChannelType.AO], nsamples)));
if (groups.ContainsKey(ChannelType.DO))
tasks.Add(Task.Factory.StartNew(() => WriteDigital(groups[ChannelType.DO], nsamples)));
Task.WaitAll(tasks.ToArray());
foreach (var task in tasks)
{
if (task.IsFaulted)
throw task.Exception;
}
}
示例5: PrintResult
public static void PrintResult(IDictionary<string, PlatformResult> dict)
{
if (dict.All(it => it.Value.Result != null))
{
if (AppVeyor)
{
PostTestResultToAppveyor(dict);
}
var result = dict.Select(it => it.Value.Result).First();
if (TeamCity)
{
Console.WriteLine("##teamcity[testStarted name='{2}.{1}.{0}' captureStandardOutput='true']",
result.Test.Name.TeamCityEncode(),
result.Test.Fixture.Name.TeamCityEncode(),
result.Test.Fixture.Assembly.Name.TeamCityEncode());
}
else if(Verbose)
{
Console.Write(result.Test.Fixture.Assembly.Name + ".");
Console.Write(result.Test.Fixture.Name + ".");
}
if (TeamCity || Verbose) {
Console.WriteLine (result.Test.Name);
}
foreach (var grpResult in dict.GroupBy(it => it.Value.Result.Kind))
{
if (Verbose || TeamCity) {
Console.Write ("{0}:", grpResult.Key);
foreach (var keyValuePair in grpResult) {
Console.Write (" ");
Console.Write (keyValuePair.Value.Platform);
}
}
if (TeamCity)
{
switch (grpResult.Key)
{
case ResultKind.Fail:
case ResultKind.Error:
Console.WriteLine(
"##teamcity[testFailed name='{2}.{1}.{0}' message='See log or details']",
result.Test.Name.TeamCityEncode(),
result.Test.Fixture.Name.TeamCityEncode(),
result.Test.Fixture.Assembly.Name.TeamCityEncode());
break;
case ResultKind.Ignore:
Console.WriteLine(
"##teamcity[testIgnored name='{2}.{1}.{0}' message='See log or details']",
result.Test.Name.TeamCityEncode(),
result.Test.Fixture.Name.TeamCityEncode(),
result.Test.Fixture.Assembly.Name.TeamCityEncode());
break;
}
}
if (Verbose || TeamCity) {
Console.WriteLine ();
}
}
if (Verbose || TeamCity) {
var span = new TimeSpan ();
foreach (var r in dict.Select(it => it.Value.Result)) {
span += (r.EndTime - r.StartTime);
}
Console.WriteLine ("avg time:{0}", new TimeSpan (span.Ticks / dict.Count));
}
if (Verbose || TeamCity) {
foreach (var lup in dict.ToLookup(it => it.Value.Result.Output)) {
var name = String.Join (",", lup.Select (it => it.Value.Platform));
Console.WriteLine ("{0}:", name);
Console.WriteLine (lup.Key);
}
}
if (TeamCity)
{
Console.WriteLine("##teamcity[testFinished name='{2}.{1}.{0}' duration='{3}']",
result.Test.Name.TeamCityEncode(),
result.Test.Fixture.Name.TeamCityEncode(),
result.Test.Fixture.Assembly.Name.TeamCityEncode(),
(result.EndTime - result.StartTime).TotalMilliseconds);
}
else
{
if (dict.Any(it => it.Value.Result.Kind == ResultKind.Fail))
{
if (Verbose)
Console.WriteLine ("!!!!!!!!!!!!!!!!!!!!!!!!!");
else if (dict.All(it => it.Value.Result.Kind == ResultKind.Fail))
Console.Write("! ");
else
Console.Write ("!{0} ", dict.Where (it => it.Value.Result.Kind == ResultKind.Fail).Count ());
}
else if (dict.Any(it => it.Value.Result.Kind == ResultKind.Error))
//.........这里部分代码省略.........
示例6: AddCondidates
public static void AddCondidates(TextBox textBox, IDictionary<string, object> dict)
{
var dict2 = AutoComplete.GetCandidates(textBox);
foreach(var grp in dict.GroupBy(pair => pair.Key, pair => pair, StringComparer.OrdinalIgnoreCase)){
dict2.Add(grp.Key, grp.ToArray());
}
}
示例7: SaveTemplate
/// <summary>
/// Saves a template file which is a all strings (needing translation) used in the entire project. Not language dependent
/// </summary>
/// <param name="items">A list of template items to save. The list should be all template items for the entire project.</param>
public void SaveTemplate(IDictionary<string, TemplateItem> items)
{
if (_settings.GenerateTemplatePerFile)
{
foreach (var item in items.GroupBy(x => x.Value.FileName))
{
SaveTemplate(item.ToDictionary(x => x.Key, x => x.Value), item.Key);
}
}
else
{
SaveTemplate(items, string.Empty);
}
}