本文整理汇总了C#中IDictionary.ToLookup方法的典型用法代码示例。如果您正苦于以下问题:C# IDictionary.ToLookup方法的具体用法?C# IDictionary.ToLookup怎么用?C# IDictionary.ToLookup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDictionary
的用法示例。
在下文中一共展示了IDictionary.ToLookup方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Assertion
/// <summary>
/// Creates a new Assertion with the supplied principal name and Assertion attributes,
/// a ValidFromDate of now, and no ValidUntilDate.
/// </summary>
/// <param name="principalName">the Principal name associated with this Assertion.</param>
/// <param name="attributes">
/// the key/value pairs for the attributes to associate with this Assertion.
/// </param>
public Assertion(string principalName, IDictionary<string, IList<string>> attributes)
{
CommonUtils.AssertNotNull(principalName, "principalName cannot be null.");
CommonUtils.AssertNotNull(attributes, "attributes cannot be null.");
this.PrincipalName = principalName;
this.ValidFromDate = DateTime.Now;
this.Attributes = attributes.ToLookup(x => x.Key, x => x.Value);
}
示例2: setCustomParameters
/// <summary>
/// Stores custom parameters to be included in the validation URL.
/// </summary>
/// <param name="customParameters">custom parameters for the validation</param>
public void setCustomParameters(IDictionary<string, string> customParameters)
{
this.customParameters = customParameters.ToLookup(x => x.Key, x => x.Value);
}
示例3: 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))
//.........这里部分代码省略.........
示例4: GetTopPlayerByScore
private static Player GetTopPlayerByScore(IDictionary<Player, int> scores)
{
return GetTopPlayerByScore(scores.ToLookup(kvp => kvp.Value, kvp => kvp.Key));
}
示例5: WaitForCompletionOrBailOutAsync
private async Task<SearchResult<IPackageSearchMetadata>> WaitForCompletionOrBailOutAsync(
string searchText,
IDictionary<string, Task<SearchResult<IPackageSearchMetadata>>> searchTasks,
CancellationToken cancellationToken)
{
if (searchTasks.Count == 0)
{
return SearchResult.Empty<IPackageSearchMetadata>();
}
var aggregatedTask = Task.WhenAll(searchTasks.Values);
RefreshToken refreshToken = null;
if (aggregatedTask != await Task.WhenAny(aggregatedTask, Task.Delay(DefaultTimeout)))
{
refreshToken = new AggregatedRefreshToken
{
SearchString = searchText,
SearchTasks = searchTasks,
RetryAfter = DefaultTimeout
};
}
var partitionedTasks = searchTasks
.ToLookup(t => t.Value.Status == TaskStatus.RanToCompletion);
var completedOnly = partitionedTasks[true];
SearchResult<IPackageSearchMetadata> aggregated;
if (completedOnly.Any())
{
var results = await Task.WhenAll(completedOnly.Select(kv => kv.Value));
aggregated = await AggregateSearchResultsAsync(searchText, results);
}
else
{
aggregated = SearchResult.Empty<IPackageSearchMetadata>();
}
aggregated.RefreshToken = refreshToken;
var notCompleted = partitionedTasks[false];
if (notCompleted.Any())
{
aggregated.SourceSearchStatus
.AddRange(notCompleted
.ToDictionary(kv => kv.Key, kv => GetLoadingStatus(kv.Value.Status)));
}
return aggregated;
}