本文整理汇总了C#中IEnumerable.ToLookup方法的典型用法代码示例。如果您正苦于以下问题:C# IEnumerable.ToLookup方法的具体用法?C# IEnumerable.ToLookup怎么用?C# IEnumerable.ToLookup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEnumerable
的用法示例。
在下文中一共展示了IEnumerable.ToLookup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateInteractorProperties
/// <summary>
/// Updates the ParentId, Z, and WindowId properties of all interactors.
/// </summary>
/// <param name="behaviorMaps">Behavior maps providing the interactors.</param>
public static void UpdateInteractorProperties(IEnumerable<BehaviorMap> behaviorMaps)
{
foreach (var behaviorsByForm in behaviorMaps
.ToLookup<BehaviorMap, Form>(map => GetForm(map)))
{
var form = behaviorsByForm.Key;
if (form == null)
{
continue;
}
var windowId = form.Handle.ToString();
try
{
var interactorDictionary = behaviorsByForm
.SelectMany(map => map.Interactors)
.ToDictionary(x => x.Control);
int z = 0;
UpdateInteractorProperties(behaviorsByForm.Key, Literals.RootId, ref z, windowId, interactorDictionary);
}
catch (ArgumentException) // thrown by the ToDictionary operation
{
throw new InvalidOperationException("A control is referenced by more than one interactor.");
}
}
}
示例2: BuildHierarchy
public IEnumerable<ISiteMapNodeToParentRelation> BuildHierarchy(ISiteMap siteMap, IEnumerable<ISiteMapNodeToParentRelation> nodes)
{
var sourceNodesByParent = nodes.ToLookup(n => n.ParentKey);
var sourceNodes = new List<ISiteMapNodeToParentRelation>(nodes);
var nodesAddedThisIteration = 0;
do
{
var nodesAlreadyAdded = new HashSet<string>();
nodesAddedThisIteration = 0;
foreach (var node in sourceNodes.OrderBy(x => x.Node.Order).ToArray())
{
if (nodesAlreadyAdded.Contains(node.Node.Key))
{
continue;
}
var parentNode = siteMap.FindSiteMapNodeFromKey(node.ParentKey);
if (parentNode != null)
{
this.AddAndTrackNode(siteMap, node, parentNode, sourceNodes, nodesAlreadyAdded);
nodesAddedThisIteration += 1;
// Add the rest of the tree branch below the current node
this.AddDescendantNodes(siteMap, node.Node, sourceNodes, sourceNodesByParent, nodesAlreadyAdded);
}
}
}
while (nodesAddedThisIteration > 0 && sourceNodes.Count > 0);
return sourceNodes;
}
示例3: DeleteFiles
internal static void DeleteFiles(this IFileSystem fileSystem, IEnumerable<IPackageFile> files, string rootDir)
{
// First get all directories that contain files
var directoryLookup = files.ToLookup(p => Path.GetDirectoryName(p.Path));
// Get all directories that this package may have added
var directories = from grouping in directoryLookup
from directory in GetDirectories(grouping.Key)
orderby directory.Length descending
select directory;
// Remove files from every directory
foreach (var directory in directories) {
var directoryFiles = directoryLookup.Contains(directory) ? directoryLookup[directory] : Enumerable.Empty<IPackageFile>();
string dirPath = Path.Combine(rootDir, directory);
if (!fileSystem.DirectoryExists(dirPath)) {
continue;
}
foreach (var file in directoryFiles) {
string path = Path.Combine(rootDir, file.Path);
fileSystem.DeleteFileSafe(path, file.GetStream);
}
// If the directory is empty then delete it
if (!fileSystem.GetFilesSafe(dirPath).Any() &&
!fileSystem.GetDirectoriesSafe(dirPath).Any()) {
fileSystem.DeleteDirectorySafe(dirPath, recursive: false);
}
}
}
示例4: AuthHeaderInfo
/// <summary>
/// Initializes a new instance of the <see cref="AuthHeaderInfo" /> class.
/// </summary>
/// <param name="name">The authentication method name</param>
/// <param name="rawValue">The raw authentication method values</param>
/// <param name="values">The parsed authentication method values</param>
/// <param name="rawValues">The raw parsed authentication method values</param>
public AuthHeaderInfo(string name, string rawValue, IEnumerable<KeyValuePair<string, string>> values, IEnumerable<KeyValuePair<string, string>> rawValues)
{
Name = name;
RawValue = rawValue;
Values = values.ToLookup(x => x.Key, x => x.Value, StringComparer.OrdinalIgnoreCase);
RawValues = rawValues.ToLookup(x => x.Key, x => x.Value, StringComparer.OrdinalIgnoreCase);
}
示例5: GetInteractors
/// <summary>
/// Gets the set of interactors within a given query rectangle.
/// </summary>
/// <param name="behaviorMaps">Behavior maps providing the interactors.</param>
/// <param name="queryRect">Query rectangle in screen coordinates.</param>
/// <param name="queryWindowIds">Window ID's from the query.</param>
/// <returns>The interactors.</returns>
public static IEnumerable<FormsInteractor> GetInteractors(IEnumerable<BehaviorMap> behaviorMaps, Rectangle queryRect, IEnumerable<string> queryWindowIds)
{
var windowIdArray = queryWindowIds.ToArray(); // avoid multiple traversals of the enumeration
foreach (var behaviorsByForm in behaviorMaps
.ToLookup<BehaviorMap, Form>(map => GetForm(map)))
{
var form = behaviorsByForm.Key;
if (form == null)
{
continue;
}
var windowId = form.Handle.ToString();
if (!windowIdArray.Contains(windowId))
{
continue;
}
// Find all interactors intersecting the query rectangle.
// Since controls cannot extend outside the bounds of their parent controls/forms
// in Windows Forms, we know that this operation will find all parent interactors
// as well.
foreach (var interactor in behaviorsByForm
.SelectMany(map => map.GetIntersectingInteractors(queryRect)))
{
yield return interactor;
}
}
}
示例6: GetUnreadCount
public UnreadCount GetUnreadCount(IEnumerable<string> addresses, DateTime time)
{
var smsCount = 0;
var emailCount = 0;
var missedCallCount = 0;
var lookUpAddressIsEmail = addresses.ToLookup(a => a.Contains("@"));
if (lookUpAddressIsEmail[true].Any())
{
emailCount = _emailService.GetEmailNewerThanDateTimeCount(lookUpAddressIsEmail[true], time);
}
if (lookUpAddressIsEmail[false].Any())
{
smsCount = _smsService.GetSmsNewerThanDateTimeCount(lookUpAddressIsEmail[false], time);
missedCallCount = _callService.GetMissedCallsNewerThanDateTime(lookUpAddressIsEmail[false], time);
}
var lastContact = GetLastContacted(lookUpAddressIsEmail);
return new UnreadCount
{
UnreadEmailCount = emailCount,
UnreadSmsCount = smsCount,
MissedCallsCount = missedCallCount,
SinceTime = time,
LastContact = lastContact != DateTime.MinValue ? lastContact : null
};
}
示例7: Ho_Nrel_Get
public List<CellName> Ho_Nrel_Get(IEnumerable<小区切换查询> cdd_nrel)
{
var nrelation = cdd_nrel.ToLookup(e => e.小区名);
List<CellName> nrel = new List<CellName>();
int thr = 0;
foreach (var n in nrelation)
{
var nreltop = n.OrderByDescending(e => e.切换次数);
foreach (var nn in nreltop)
{
thr++;
if (thr > 5) continue;
CellName cn = new CellName();
cn.Cell_name = n.Key;
cn.N_cell_name = nn.邻小区名;
cn.Handover = nn.切换次数;
nrel.Add(cn);
}
thr = 0;
}
foreach (var n in nrelation)
{
CellName cn = new CellName();
cn.Cell_name = n.Key;
cn.N_cell_name = n.Key;
nrel.Add(cn);
}
return nrel;
}
示例8: ToExpando
/// <summary>
/// Turns the given object <paramref name="obj"/> into an <see cref="ExpandoObject"/>.
/// If <paramref name="obj"/> is:
/// <list type="bullet">
/// <item><description>
/// <see langword="null"/> then a new empty <see cref="ExpandoObject"/> is returned.
/// </description></item>
/// <item><description>
/// <see cref="NameValueCollection"/>, <see cref="IDictionary"/>, <see cref="ExpandoObject"/> or any
/// <see cref="IDictionary{TKey,TValue}"/> then a new expando object with the same source key-value pairs
/// is created and returned. Keys are converted to strings if they are not of type <see cref="String"/>.
/// </description></item>
/// <item><description>
/// <see cref="IDataRecord"/> then a new expando objet with the same column name-value pair of the current rader
/// row is created and returned. All <see cref="DBNull"/> values are converted to <see langword="null"/> or to the default
/// value of the hint type if a <paramref name="typeHint"/> parameter is provided.
/// </description></item>
/// </list>
/// </summary>
/// <param name="obj">The source object to convert to an expando object.</param>
/// <param name="typeHint">Object or dictionary with values of type <see cref="Type"/>.</param>
/// <param name="whitelist">Exhaustive set of properties to include.</param>
/// <param name="blacklist">Poperties to exclude.</param>
public static ExpandoObject ToExpando(
this object obj,
object typeHint = null,
IEnumerable<string> whitelist = null,
IEnumerable<string> blacklist = null)
{
if (obj == null)
{
return new ExpandoObject();
}
var includeLookup = whitelist == null ? null : whitelist.ToLookup(x => x);
var excludeLookup = blacklist == null ? null : blacklist.ToLookup(x => x);
if (whitelist != null && blacklist != null && includeLookup.Any() && includeLookup.Any())
{
// Slicing can't be done by both including *and* excluding properties
throw new InvalidOperationException("Slicing is done using either a white list or a black list");
}
var types = typeHint == null
? null
: typeHint.ToExpando().Where(p => p.Value is Type).ToDictionary(p => p.Key, p => (Type)p.Value);
var result = new ExpandoObject();
var resultDictionary = result as IDictionary<string, object>;
ObjectConversionHelper.ProcessProperties(
obj,
(key, val) => resultDictionary[key] = ChangeType(key, val, types),
key => FilterProperty(includeLookup, excludeLookup, key));
return result;
}
示例9: IntersectProperties
/// <summary>
/// Filters properties in this instance by specified property identifiers.
/// </summary>
/// <param name="propertyIds">The property identifiers.</param>
/// <exception cref="System.ArgumentNullException">propertyIds</exception>
public void IntersectProperties(IEnumerable<int> propertyIds)
{
if (propertyIds == null) throw new ArgumentNullException("propertyIds");
ILookup<int, int> requiredIds = propertyIds.ToLookup(t => t);
Properties = Properties.Where(p => requiredIds.Contains(p.PropertyId)).ToArray();
}
示例10: LunchOptionViewModel
public LunchOptionViewModel(int pollId, LunchOption lo, IEnumerable<LunchVote> votes)
{
Id = lo.Id;
PollId = pollId;
Name = lo.Name;
var vLookup = votes.ToLookup(v => v.Score, v => v.User.UserName);
Upvotes = vLookup[1].OrderBy(n => n).ToList();
Downvotes = vLookup[-1].OrderBy(n => n).ToList();
}
示例11: Verify
public void Verify(IEnumerable<SecurityAttributeDescriptor> descriptors)
{
var descriptorLookup = descriptors.ToLookup(d => d.Signature);
foreach (TypeDefinition type in _assembly.MainModule.Types)
{
AssertDescriptorMatches(descriptorLookup, type.FullName, type);
foreach (MethodDefinition method in type.AllMethodsAndConstructors())
AssertDescriptorMatches(descriptorLookup, SignatureFor(method), method);
}
}
示例12: GetMembersSlow
private static IReadOnlyList<DeclarationReference> GetMembersSlow(IEnumerable<Declaration> symbols)
{
var lookup = symbols
.ToLookup(s => s is Namespace);
var childSymbols = lookup[false].Cast<Entity>()
.Select(e => (DeclarationReference)new EntityReference(e)).ToList();
var childNamespaces = lookup[true].ToList();
if(childNamespaces.Any())
{
var childNamespace = new NamespaceReference(childNamespaces.Cast<Namespace>());
childSymbols.Add(childNamespace);
}
return childSymbols;
}
示例13: OverrideDependenciesWithLocalDeclarations
IEnumerable<ResolvedDependency> OverrideDependenciesWithLocalDeclarations(IEnumerable<ResolvedDependency> dependencies, ICollection<WrapDependency> rootDependencies)
{
var overriddenDependencies = dependencies.ToList();
foreach(var conflictingDependency in dependencies.ToLookup(x=>x.Package.Name).Where(x=>x.Count() > 1))
{
var dependencyName = conflictingDependency.Key;
var rootDependency = rootDependencies.FirstOrDefault(x => x.Name == dependencyName);
if (rootDependency == null)
continue;
var rescuedDependency = conflictingDependency.OrderByDescending(x => x.Package.Version).FirstOrDefault(x => rootDependency.IsFulfilledBy(x.Package.Version));
if (rescuedDependency == null)
continue;
foreach (var toRemove in conflictingDependency.Where(x=>x != rescuedDependency))
overriddenDependencies.Remove(toRemove);
}
return overriddenDependencies;
}
示例14: ForTimer
public static AutoCompleteController ForTimer(IEnumerable<Toggl.TogglAutocompleteView> items)
{
var splitList = items.ToLookup(i => string.IsNullOrEmpty(i.Description));
var entries = splitList[false];
var projects = splitList[true];
int entriesCount;
int projectsCount;
var list = new List<IAutoCompleteListItem>
{
new SimpleNoncompletingCategory("Time Entries",
entries.Select(i => new TimerItem(i, false)).ToList<IAutoCompleteListItem>().GetCount(out entriesCount)
),
new SimpleNoncompletingCategory("Projects",
projects.Select(i => new TimerItem(i, true)).ToList<IAutoCompleteListItem>().GetCount(out projectsCount)
)
};
return new AutoCompleteController(list, string.Format("Timer(entries: {0}, projects: {1})", entriesCount, projectsCount));
}
示例15: SetReferenceLocations
private void SetReferenceLocations(IEnumerable<InlineRenameLocation> locations)
{
AssertIsForeground();
var locationsByDocument = locations.ToLookup(l => l.Document.Id);
_isApplyingEdit = true;
foreach (var textBuffer in _openTextBuffers.Keys)
{
var documents = textBuffer.AsTextContainer().GetRelatedDocuments();
if (!documents.Any(d => locationsByDocument.Contains(d.Id)))
{
_openTextBuffers[textBuffer].SetReferenceSpans(SpecializedCollections.EmptyEnumerable<TextSpan>());
}
else
{
var spans = documents.SelectMany(d => locationsByDocument[d.Id]).Select(l => l.TextSpan).Distinct();
_openTextBuffers[textBuffer].SetReferenceSpans(spans);
}
}
_isApplyingEdit = false;
}