本文整理汇总了C#中IList.ToLookup方法的典型用法代码示例。如果您正苦于以下问题:C# IList.ToLookup方法的具体用法?C# IList.ToLookup怎么用?C# IList.ToLookup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IList
的用法示例。
在下文中一共展示了IList.ToLookup方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DescribeCandidateProcesses
public void DescribeCandidateProcesses(IList<IProcessInfo> candidates, ConsoleLog console)
{
var byArchitecture = candidates.ToLookup(c => c.Architecture);
var self = ProcessArchitecture.FromCurrentProcess();
if(self is ProcessArchitecture.x86)
{
if(!x86Thunk.Bootstrap.WasUsed)
{
// Native x86. Write out everything.
WriteProcessList(candidates, console);
}
else
{
// Write out only matching processes.
WriteProcessList(byArchitecture[self].ToList(), console);
}
}
else
{
WriteProcessList(byArchitecture[self].ToList(), console);
if(byArchitecture[new ProcessArchitecture.x86()].Any())
{
// Go to 32-bit and render the rest of the process information.
Bootstrap.RecurseInto32BitProcess();
}
}
}
示例2: Match
public IEnumerable<IssueMatch> Match (IList<ActionSummary> summaries, IList<CodeAction> realActions)
{
var summaryLookup = summaries.ToLookup (summary => summary.Region);
foreach (var action in realActions) {
if (summaryLookup.Contains (action.DocumentRegion)) {
yield return new IssueMatch {
Action = action,
Summary = summaryLookup[action.DocumentRegion].First ()
};
}
}
}
示例3: GuardarRedes
public void GuardarRedes(IList<Resultado> lista, string archivo, IList<FichaIndicadores> fichas)
{
var map = fichas.ToDictionary(x => x.Nombre);
var grupos = lista.ToLookup(x => x.Tipo_item);
using (var pck = new ExcelPackage(new FileInfo(archivo))) {
try {
foreach (var grupo in grupos) {
if (!map.ContainsKey(grupo.Key))
continue;
Ficha = map[grupo.Key];
CrearHoja(grupo.ToList(), Ficha.Nombre, pck);
}
pck.Save();
} catch (Exception ex) {
AppNotifier.Print("Error " + ex.Message, ex);
}
}
}
示例4: Judge
public IList<Result> Judge(IList<IPlayer> playerList)
{
if (playerList == null) {
throw new ArgumentNullException("player is missing");
}
if (playerList.Count < 1) {
throw new ArgumentException("MajorityDecision need one person or more.");
}
var handLookup = playerList.ToLookup(player => player.ChoosedHand);
if (handLookup.Count == 1) {
return playerList.Map(player => new Result(player, ResultType.Draw));
}
var maxCount = handLookup.Max(hand => handLookup[hand.Key].Count());
if (handLookup.Count(group => group.Count() == maxCount) > 1) {
return playerList.Map(player => new Result(player, ResultType.Draw));
}
var winHand = handLookup.First(group => group.Count() == maxCount).Key;
return playerList.Map(player => new Result(player, player.ChoosedHand.Equals(winHand) ? ResultType.Win : ResultType.Lose));
}
示例5: FindLongestNonOverlappingRangeSet
/// <summary>
/// create a hashtable of start->list of tuples that start there
/// put all tuples in a queue of tupleSets
/// set the longestTupleSet to the first tuple
/// while the queue is not empty
/// take tupleSet from the queue
/// if any tuples start where the tupleSet ends
/// foreach tuple that starts where the tupleSet ends
/// enqueue new tupleSet of tupleSet + tuple
/// continue
///
/// if tupleSet is longer than longestTupleSet
/// replace longestTupleSet with tupleSet
///
/// return longestTupleSet
/// </summary>
/// <param name = "input"></param>
/// <returns></returns>
public static IList<Pair<int, int>> FindLongestNonOverlappingRangeSet(IList<Pair<int, int>> input)
{
var rangeStarts = input.ToLookup(x => x.First, x => x);
var adjacentTuples = new Queue<List<Pair<int, int>>>(
input.Select(x => new List<Pair<int, int>>
{
x
}));
var longest = new List<Pair<int, int>>
{
input[0]
};
int longestLength = input[0].Second - input[0].First;
while (adjacentTuples.Count > 0)
{
var tupleSet = adjacentTuples.Dequeue();
var last = tupleSet.Last();
int end = last.First + last.Second;
var sameStart = rangeStarts[end];
if (sameStart.Any())
{
foreach (var nextTuple in sameStart)
{
adjacentTuples.Enqueue(tupleSet.Concat(new[] { nextTuple }).ToList());
}
continue;
}
int length = end - tupleSet.First().First;
if (length > longestLength)
{
longestLength = length;
longest = tupleSet;
}
}
return longest;
}
示例6: ReplaceIndexersCalls
public void ReplaceIndexersCalls(MethodDefinition method, IList<SliceParameters> slices)
{
var processor = method.Body.GetILProcessor();
var instructions = processor.Body.Instructions;
var slicesLookup = slices.ToLookup(x => x.Definition);
for (int offset = 0; offset < instructions.Count; offset++)
{
var instruction = instructions[offset];
if (!instruction.OpCode.IsCall())
continue;
var methodReference = instruction.Operand as MethodReference;
if (methodReference == null)
continue;
if (methodReference.Name != "get_Item" && methodReference.Name != "set_Item")
continue;
var objectToCall = instruction.TraceBack(methodReference, 0);
var parameter = instruction.TraceBack(methodReference, -1);
var slice = slicesLookup[objectToCall.Operand].FirstOrDefault();
if (slice == null)
continue;
var arraySliceType = ModuleDefinition.Import(typeof(ArraySlice<>)).MakeGenericInstanceType(slice.GenericArgument);
var methodDefinition = methodReference.Resolve();
// FIXME: We know we cannot process if anything happens between the push of the array slice and the final operation.
if (methodDefinition.IsGetter)
{
// Original GET:
// 1 ldarg.s segment $ Push the object to call
// = ldloc.1 $ Push the parameter
// 2 callvirt instance !0 class ArraySegment.ArraySlice`1<float32>::get_Item(int32)
// = stloc.s t $ Do whatever with the result of the GET call
// Target GET:
// 1 ldloc.s data $ Push the object to call
// = ldloc.1 $ Push the parameter
// 2 ldloc.s offset
// 2 add $ Add the parameter (i) and the offset.
// 2 ldelem.r4 $ Use standard ldelem with type to get the value from the array.
// = stloc.s t $ Do whatever with the result of the GET call
//HACK: We rewrite it to avoid killing the loop.
objectToCall.OpCode = OpCodes.Ldloc;
objectToCall.Operand = slice.ArrayVariable;
processor.Replace(instruction, Instruction.Create(OpCodes.Ldelem_Any, slice.GenericArgument));
processor.InsertAfter(parameter, new[] {
Instruction.Create( OpCodes.Ldloc, slice.OffsetVariable ),
Instruction.Create( OpCodes.Add )
});
}
else if (methodDefinition.IsSetter)
{
// Original SET:
// 1 ldarg segment $ Push the object to call
// = ldloc.0 $ Push the parameter
// = ldc.r4 2 $ Push the value to set
// 2 callvirt instance void class ArraySegment.ArraySlice`1<float32>::set_Item(int32, !0)
// - nop $ Check if it even exists after SimplifyMacros in the collection.
// Target SET
// 1 ldloc data $ Push the array
// = ldloc.0 $ Push the parameter
// 2 ldloc offset
// 2 add $ Add the parameter (i) and the offset.
// = ldc.r4 2 $ Push the value to set. Use standard ldc with type and check if it is optimized afterwards.
// 2 stelem $ Use standard stelem with type and check if it is optimized afterwards.
//HACK: We rewrite it to avoid killing the loop.
objectToCall.OpCode = OpCodes.Ldloc;
objectToCall.Operand = slice.ArrayVariable;
processor.Replace(instruction, Instruction.Create(OpCodes.Stelem_Any, slice.GenericArgument));
processor.InsertAfter(parameter, new[] {
Instruction.Create( OpCodes.Ldloc, slice.OffsetVariable ),
Instruction.Create( OpCodes.Add )
});
}
else continue;
}
}
示例7: ApplyPendingDownloadIncrements
public void ApplyPendingDownloadIncrements(IList<LucenePackage> increments, ISession<LucenePackage> session)
{
if (increments.Count == 0) return;
var byId = increments.ToLookup(p => p.Id);
foreach (var grouping in byId)
{
var packageId = grouping.Key;
var packages = from p in session.Query() where p.Id == packageId select p;
var byVersion = grouping.ToLookup(p => p.Version);
foreach (var lucenePackage in packages)
{
lucenePackage.DownloadCount += grouping.Count();
lucenePackage.VersionDownloadCount += byVersion[lucenePackage.Version].Count();
}
}
}
示例8: FromListAndTargets
public static IList<AlbumTarget> FromListAndTargets(IList<Track> iTracks, IList<Artist> Artists, string AlbumName, string itGenre = null, int? tYear = null)
{
var res = iTracks.ToLookup(t => t.RawAlbum).ToLookup(a => new AlbumTarget(Artists ?? a.Key.RawArtists, AlbumName ?? a.Key.Name, itGenre, tYear));
return res.Apply(g => g.Key.OrderedTrack = g.Select((gg) => new OriginedGroupedTrack(gg.Key, gg.ToList(), g.Key)).ToList()).Select(g => g.Key).ToList();
}