本文整理汇总了C#中Dictionary.SelectMany方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.SelectMany方法的具体用法?C# Dictionary.SelectMany怎么用?C# Dictionary.SelectMany使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dictionary
的用法示例。
在下文中一共展示了Dictionary.SelectMany方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Detect
/// <summary>
/// Detects which expressions in a <see cref="Grammar"/> are left-adjacent.
/// </summary>
/// <param name="grammar">The <see cref="Grammar"/> to inspect.</param>
/// <returns>A <see cref="ILookup{Rule, Expression}"/> containing the left-adjacent rules.</returns>
public static ILookup<Rule, Expression> Detect(Grammar grammar)
{
var leftAdjacent = new Dictionary<Rule, List<Expression>>();
var zeroWidth = ZeroWidthEvaluator.Evaluate(grammar);
new LeftRecursionExpressionTreeWalker(zeroWidth, leftAdjacent).WalkGrammar(grammar);
return leftAdjacent.SelectMany(i => i.Value, (i, v) => new { i.Key, Value = v }).ToLookup(i => i.Key, i => i.Value);
}
示例2: Run
public void Run(BuildTarget target,
NodeData node,
ConnectionPointData inputPoint,
ConnectionData connectionToOutput,
Dictionary<string, List<Asset>> inputGroupAssets,
List<string> alreadyCached,
Action<ConnectionData, Dictionary<string, List<Asset>>, List<string>> Output)
{
var incomingAssets = inputGroupAssets.SelectMany(v => v.Value).ToList();
var modifier = ModifierUtility.CreateModifier(node, target);
UnityEngine.Assertions.Assert.IsNotNull(modifier);
bool isAnyAssetModified = false;
foreach(var asset in incomingAssets) {
var loadedAsset = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(asset.importFrom);
if(modifier.IsModified(loadedAsset)) {
modifier.Modify(loadedAsset);
isAnyAssetModified = true;
}
}
if(isAnyAssetModified) {
// apply asset setting changes to AssetDatabase.
AssetDatabase.Refresh();
}
// Modifier does not add, filter or change structure of group, so just pass given group of assets
Output(connectionToOutput, inputGroupAssets, null);
}
示例3: LetterValuePairs
private static IEnumerable<dynamic> LetterValuePairs(
Dictionary<int, IList<string>> old)
{
return old.SelectMany(
kvp => kvp.Value.Select(
letter => new {Letter = letter.ToLower(), Value = kvp.Key}));
}
示例4: TagConverter
public TagConverter(ISettingsProvider settingsProvider)
{
using (var reader = new StreamReader(settingsProvider.Get<string>(SettingsKeys.TagMappingFile)))
{
normalizedTags = reader
.ReadAllLines()
.Where(x => !string.IsNullOrWhiteSpace(x))
.Select(ParseTagDescription)
.ToDictionary(x => x.Name, x => x.RawTags);
rawTagsMapping = normalizedTags
.SelectMany(normalizedTag => normalizedTag.Value.Select(rawTag => new { Normalized = normalizedTag.Key, Raw = rawTag }))
.ToDictionary(x => x.Raw, x => x.Normalized);
}
using (var reader = new StreamReader(settingsProvider.Get<string>(SettingsKeys.CorrectionsFile)))
{
correctionsByProblemUrl = reader
.ReadAllLines()
.Where(x => !string.IsNullOrWhiteSpace(x))
.SelectMany(ParseCorrections)
.GroupBy(x => x.ProblemUrl)
.ToDictionary(x => x.Key, x => x.ToArray());
}
}
示例5: FakeDataQueue
/// <summary>
/// Initializes a new instance of the <see cref="FakeDataQueue"/> class to randomly emit data for each symbol
/// </summary>
public FakeDataQueue()
{
_ticks = new ConcurrentQueue<BaseData>();
_symbols = new Dictionary<SecurityType, List<string>>();
_timer = new Timer
{
AutoReset = true,
Enabled = true
};
_timer.Elapsed += (sender, args) =>
{
_timer.Interval = _random.Next(15, 2500); // around each second
foreach (var symbol in _symbols.SelectMany(x => x.Value))
{
// 50/50 repeating chance of emitting each symbol
while (_random.NextDouble() > 0.75)
{
_ticks.Enqueue(new Tick
{
Time = DateTime.Now,
Symbol = symbol,
Value = 10 + (decimal) Math.Abs(Math.Sin(DateTime.Now.TimeOfDay.TotalMinutes)),
TickType = TickType.Trade,
Quantity = _random.Next(10, (int) _timer.Interval)
});
}
}
};
}
示例6: Given_30_New_Feeds_GetLatest_Returns_Feeds_In_Correct_Order
public void Given_30_New_Feeds_GetLatest_Returns_Feeds_In_Correct_Order()
{
var urlFeeds = new Dictionary<string, IEnumerable<Item>>
{
{ "http://atom1", BuildFeeds(5) },
{ "http://atom2", BuildFeeds(10) },
{ "http://atom3", BuildFeeds(15) }
};
var minDate = urlFeeds.SelectMany(kv => kv.Value).Select(f => f.Published).Min();
var maxDate = urlFeeds.SelectMany(kv => kv.Value).Select(f => f.Published).Max();
var rssAggregator = BuildRssAggregator(urlFeeds);
var feeds = rssAggregator.GetLatest(DateTime.MinValue).ToList();
Assert.AreEqual(minDate, feeds.First().Published);
Assert.AreEqual(maxDate, feeds.Last().Published);
}
示例7: Given_30_New_Tweets_GetLatest_Returns_Tweets_In_Correct_Order
public void Given_30_New_Tweets_GetLatest_Returns_Tweets_In_Correct_Order()
{
var queryTweets = new Dictionary<string, IEnumerable<Item>>
{
{ "#hashtag", BuildTweets(5) },
{ "@user", BuildTweets(10) },
{ "text", BuildTweets(15) }
};
var minDate = queryTweets.SelectMany(kv => kv.Value).Select(f => f.Published).Min();
var maxDate = queryTweets.SelectMany(kv => kv.Value).Select(f => f.Published).Max();
var twitterAggregator = BuildTwitterAggregator(queryTweets);
var tweets = twitterAggregator.GetLatest(DateTime.MinValue).ToList();
Assert.AreEqual(minDate, tweets.First().Published);
Assert.AreEqual(maxDate, tweets.Last().Published);
}
示例8: GetDistinctFieldCodes
private string[] GetDistinctFieldCodes(Dictionary<TemplateModel, List<FieldCodeSummaryModel>> analysisData)
{
var distinctFieldCodes = new List<string>();
foreach (var fieldCodeSummary in analysisData.SelectMany(i => i.Value.Where(fc => !distinctFieldCodes.Contains(fc.ColumnName))))
{
distinctFieldCodes.Add(fieldCodeSummary.ColumnName);
}
return distinctFieldCodes.OrderBy(fc => fc).ToArray();
}
示例9: GetItems
public IEnumerable<BlogPost> GetItems(int feedCount = 20, int pagenum = 0)
{
string json = File.ReadAllText("feeddata.json");
var metadataEntries = json.FromJson<MetaData[]>();
var syndicationFeeds = new Dictionary<string, SyndicationFeed>();
foreach (var metadata in metadataEntries)
{
var reader = XmlReader.Create(metadata.FeedUrl);
var feed = SyndicationFeed.Load(reader);
reader.Close();
if (feed != null)
{
syndicationFeeds.Add(metadata.Id, feed);
}
}
var data = syndicationFeeds
.SelectMany(pair => pair.Value.Items, (pair, item) => new { Id = pair.Key, Item = item })
.Where(x => x.Item.Categories.Any(y => y.Name.ToLower() == "nancy" || y.Name.ToLower() == "nancyfx"))
.Select(x =>
{
var rssauthor = x.Item.Authors.FirstOrDefault();
var metaauthor = metadataEntries.FirstOrDefault(y => y.Id == x.Id);
var authorname = string.Empty;
var authoremail = string.Empty;
if (metaauthor != null)
{
authorname = rssauthor == null ? metaauthor.Author : rssauthor.Name;
authoremail = rssauthor == null ? metaauthor.AuthorEmail : rssauthor.Email;
}
var link = x.Item.Links.FirstOrDefault();
var locallink = link == null ? string.Empty : link.Uri.PathAndQuery;
var originallink = link == null ? string.Empty : link.Uri.AbsoluteUri;
return new BlogPost
{
Title = x.Item.Title.Text,
Summary = x.Item.Summary.Text,
Author = authorname,
AuthorEmail = authoremail,
Localink = locallink,
OriginalLink = originallink
};
})
.Skip(feedCount * pagenum)
.Take(feedCount)
.OrderByDescending(x => x.PublishedDate)
;
return data;
}
示例10: Search
public List<Fork> Search(Dictionary<SportType, Dictionary<GameInfo, List<Game>>> games)
{
if (games == null)
{
throw new ArgumentNullException(nameof(games));
}
return games.SelectMany(pair => this.GetForks(pair.Key, pair.Value)).ToList();
}
示例11: Job
public Job(string name, string rowScope, Dictionary<string, List<Column>> capturePathToColumns, TextWriter textWriter)
{
_rowScope = rowScope;
_capturePathToColumn = capturePathToColumns;
Name = name;
List<string> columnNames = capturePathToColumns.SelectMany(x => x.Value.Select(y => y.Name)).ToList();
Writer = new Writer(columnNames, textWriter);
}
示例12: FakeNewsServer
public FakeNewsServer(Dictionary<int, int[]> channelsByAccount)
{
var endDate = DateTime.Now.AddHours(-1);
var startDate = endDate.AddDays(-40);
this.channelsByAccount = channelsByAccount;
var channels = channelsByAccount.SelectMany(ca => ca.Value).Distinct();
newsByChannel = channels.ToDictionary(c => c,
c => NewsMaker.MakeSomeNews(c, startDate, endDate, 1,
random.Next(100) < 50
? random.Next(1, 10)
: random.Next(2, 1440)));
}
示例13: GetPJL
public static byte[] GetPJL(Dictionary<string, string> jobattribs, Dictionary<string, string> pjlsettings, string language)
{
return Encoding.ASCII.GetBytes(
"\x1B%-12345X".ToArray()
.Concat("@PJL JOB MODE=PRINTER\r\n")
.Concat(jobattribs == null ? new char[] { } : jobattribs.SelectMany(kvp => "@PJL SET JOBATTR=\"@".ToArray().Concat(kvp.Key).Concat("=").Concat(kvp.Value).Concat("\"\r\n")))
.Concat(pjlsettings == null ? new char[] { } : pjlsettings.SelectMany(kvp => "@PJL SET ".ToArray().Concat(kvp.Key).Concat("=").Concat(kvp.Value).Concat("\r\n")))
.Concat("@PJL ENTER LANGUAGE=")
.Concat(language)
.Concat("\r\n")
.ToArray()
);
}
示例14: TestDetectionEngine
public void TestDetectionEngine()
{
Dictionary<string, IList<ISoundSignalReader>> learningWordSignals = new Dictionary<string, IList<ISoundSignalReader>>();
Dictionary<string, IList<ISoundSignalReader>> testWordSignals = new Dictionary<string, IList<ISoundSignalReader>>();
var learningDirectories = Directory.GetDirectories("Sounds\\Learning");
var testDirectories = Directory.GetDirectories("Sounds\\test");
foreach (var directory in learningDirectories.Where(item => !item.Contains("catalog")))
{
var word = new DirectoryInfo(directory).Name;
learningWordSignals.Add(word, new List<ISoundSignalReader>());
var wavFiles = Directory.GetFiles(directory).Select(item => new FileInfo(item)).Where(fItem => fItem.Extension.Contains("wav"));
foreach (var file in wavFiles)
{
learningWordSignals[word].Add(new WavSoundSignalReader(file.FullName));
}
}
foreach (var directory in testDirectories)
{
var word = new DirectoryInfo(directory).Name;
testWordSignals.Add(word, new List<ISoundSignalReader>());
var wavFiles = Directory.GetFiles(directory).Select(item => new FileInfo(item)).Where(fItem => fItem.Extension.Contains("wav"));
foreach (var file in wavFiles)
{
testWordSignals[word].Add(new WavSoundSignalReader(file.FullName));
}
}
var catalogSignals = new List<ISoundSignalReader>();
catalogSignals.AddRange(learningWordSignals.SelectMany(item => item.Value));
var codeBook = CodeBookFactory.FromWaves(catalogSignals, EngineParameters.Default);
var recognitionEngine = new DetectionEngine(codeBook);
var result = recognitionEngine.Train(learningWordSignals);
foreach (var word in testWordSignals)
{
foreach (var signal in word.Value)
{
string name;
var value = recognitionEngine.Recognize(signal, out name);
Assert.AreEqual(word.Key, name);
}
}
}
示例15: Process
/// <summary>
/// Process the content of Claim files and change to structure we want for Result file
/// </summary>
/// <param name="rows">content of claim file</param>
/// <returns></returns>
public ProcessClaimFileResult Process(Dictionary<string, Dictionary<int, List<BaseClaimRowMetaData>>> rows)
{
if (!rows.Any())
{
//We can throw Exception here too, depend on our policies
return new ProcessClaimFileResult{Exception = new ProcessFileRowNotFoundException() };
}
var originYears = rows.SelectMany(r => r.Value.Select(v => v.Key)).Distinct().OrderBy(o => o).ToArray();
_earliestOriginYear = originYears.First();
_lastDevelopmentYear = originYears.Last();
_numberOfDevelopment = _lastDevelopmentYear - _earliestOriginYear + 1;
var accumulatedTriangle = CalculateAccumulatedTriangle(rows);
return new ProcessClaimFileResult { EarliestOriginYear = _earliestOriginYear, NumberOfDevelopment = _numberOfDevelopment, AccumulatedTriangle = accumulatedTriangle };
}